// 用来全局控制 上一周,本周,下一周的周数变化
private static int weeks = 0;
// 获得当前日期与本周一相差的天数
private int getMondayPlus() {
Calendar cd = Calendar.getInstance();
// 获得今天是一周的第几天,星期日是第一天,星期二是第二天......
int dayOfWeek = cd.get(Calendar.DAY_OF_WEEK);
if (dayOfWeek == 1) {
return -6;
} else {
return 2 - dayOfWeek;
}
}
// 获得上周星期一的日期
public String getPreviousMonday() {
weeks--;
int mondayPlus = this.getMondayPlus();
GregorianCalendar currentDate = new GregorianCalendar();
currentDate.add(GregorianCalendar.DATE, mondayPlus + 7 * weeks);
Date monday = currentDate.getTime();
DateFormat df = DateFormat.getDateInstance();
String preMonday = df.format(monday);
return preMonday;
}
// 获得上周星期一的日期
public String getCurrentMonday() {
weeks = 0;
int mondayPlus = this.getMondayPlus();
GregorianCalendar currentDate = new GregorianCalendar();
currentDate.add(GregorianCalendar.DATE, mondayPlus);
Date monday = currentDate.getTime();
DateFormat df = DateFormat.getDateInstance();
String preMonday = df.format(monday);
return preMonday;
}
// 获得上周星期一的日期
public String getNextMonday() {
weeks++;
int mondayPlus = this.getMondayPlus();
GregorianCalendar currentDate = new GregorianCalendar();
currentDate.add(GregorianCalendar.DATE, mondayPlus + 7 * weeks);
Date monday = currentDate.getTime();
DateFormat df = DateFormat.getDateInstance();
String preMonday = df.format(monday);
return preMonday;
}
// 获得相应周的周日的日期
public String getSunday() {
int mondayPlus = this.getMondayPlus();
GregorianCalendar currentDate = new GregorianCalendar();
currentDate.add(GregorianCalendar.DATE, mondayPlus + 7 * weeks + 6);
Date monday = currentDate.getTime();
DateFormat df = DateFormat.getDateInstance();
String preMonday = df.format(monday);
return preMonday;
}
阅读(1362) | 评论(0) | 转发(0) |
0
上一篇:Struts前端验证
下一篇:Java日期计算
相关热门文章
- 承接自动化测试培训、外包、实...
- Solaris PowerTOP 1.0 发布
- For STKMonitor
- 项目小体会
- busybox的httpd使用CGI脚本(Bu...
- php集成环境和自己配置的区别...
- flash播放控件
- 查看nginx某一时段的日志...
- ftp服务器日志分析
- mpi 目标机器积极拒绝,下面错...