日期操作相關
public boolean checkCourseTimes(List schedules, Long schoolId){
boolean flag=false;
if(schedules==null)return false;
schedules.remove(null);
Collections.sort(schedules, new Comparator() {
public int compare(Object a, Object b) {
Schedule cs1 = (Schedule) a;
Schedule cs2 = (Schedule) b;
if(cs1==null||cs2==null)return 0;
Date cs1date=cs1.getStartTime();
Date cs2date=cs2.getStartTime();
int temp=cs1date.compareTo(cs2date);
return temp;
}
});
//firt day
Schedule firtsch=(Schedule)schedules.get(0);
Date firstday=firtsch.getStartTime();
Calendar ca=Calendar.getInstance();
ca.setTime(firstday);
int step = ca.get(Calendar.DAY_OF_WEEK);
ca.add(Calendar.DATE, -step);
Date weekFirstDay = ca.getTime();
//last day
Schedule lastsch=(Schedule)schedules.get(0);
Date lastday=firtsch.getStartTime();
ca.setTime(lastday);
step = 7 - ca.get(Calendar.DAY_OF_WEEK);
ca.add(Calendar.DATE, step);
Date weekLastDay = ca.getTime();
long subs = weekLastDay.getTime()-weekFirstDay.getTime();
long betweenDays = (long)(subs / (1000 * 60 * 60 *24) + 0.5);
int weeks=(int)(betweenDays / 7+0.5);
return flag;
}[@more@]
boolean flag=false;
if(schedules==null)return false;
schedules.remove(null);
Collections.sort(schedules, new Comparator() {
public int compare(Object a, Object b) {
Schedule cs1 = (Schedule) a;
Schedule cs2 = (Schedule) b;
if(cs1==null||cs2==null)return 0;
Date cs1date=cs1.getStartTime();
Date cs2date=cs2.getStartTime();
int temp=cs1date.compareTo(cs2date);
return temp;
}
});
//firt day
Schedule firtsch=(Schedule)schedules.get(0);
Date firstday=firtsch.getStartTime();
Calendar ca=Calendar.getInstance();
ca.setTime(firstday);
int step = ca.get(Calendar.DAY_OF_WEEK);
ca.add(Calendar.DATE, -step);
Date weekFirstDay = ca.getTime();
//last day
Schedule lastsch=(Schedule)schedules.get(0);
Date lastday=firtsch.getStartTime();
ca.setTime(lastday);
step = 7 - ca.get(Calendar.DAY_OF_WEEK);
ca.add(Calendar.DATE, step);
Date weekLastDay = ca.getTime();
long subs = weekLastDay.getTime()-weekFirstDay.getTime();
long betweenDays = (long)(subs / (1000 * 60 * 60 *24) + 0.5);
int weeks=(int)(betweenDays / 7+0.5);
return flag;
}[@more@]
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/106285/viewspace-874024/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SQL Server 日期相關SQLServer
- SQL 日期格式相關函式SQL函式
- Django筆記十五之in查詢及date日期相關過濾操作Django筆記
- MongoDB相關操作MongoDB
- 列表及相關操作
- 字典及相關操作
- Cookie的相關操作Cookie
- 【基本操作】RMAN 相關
- pip 相關命令操作
- Word的相關操作
- Oracle關於時間/日期的操作Oracle
- oracle關於分割槽相關操作Oracle
- Redis 相關運維操作Redis運維
- 基礎IO相關操作
- git 撤銷相關操作Git
- 時間相關的操作
- javascript時間日期相關內容介紹JavaScript
- SQL SERVER 日期相關性優化選項SQLServer優化
- sqlite相關--------adb shell操作,工具操作,程式操作SQLite
- DDL、DML、DCL、DQL相關操作
- Linux相關的操作指令Linux
- MySQL 之慢查詢相關操作MySql
- iOS狀態列相關操作iOS
- VIM 字元編碼相關操作字元
- db2look相關操作DB2
- 廣義表的相關操作
- Oracle表空間相關操作Oracle
- git相關操作,個人記錄Git
- StringBuilder類相關操作UI
- Flutter空安全相關操作符Flutter
- python的字典及相關操作Python
- Mac開發相關設定操作Mac
- jQuery陣列相關操作程式碼jQuery陣列
- c語言檔案操作相關C語言
- 【原創】表空間相關操作
- mini-lsm通關筆記-字元相關操作筆記字元
- HBase篇--HBase操作Api和Java操作Hbase相關ApiAPIJava
- 日期操作積累