比如我现在的时间2012-03-21,我想得到它这一周的星期四的日期,也就是2012-03-22,请问这我得怎么得到呢?
解决方案 »
- struts2如何把oracle的值显示到页面呢?如何做分页呢?
- 求解Hibernate一对多级联删除问题
- javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
- you have an error in your sql syntax;check the manual
- 关于 ssh 的初级问题
- struts2标签
- 求助: 如何设置weblogic中某bean实例的个数?
- 如何在win98下运行jboss3.2.5??100分送
- websocket中进行Spring依赖注入service方法,报错?
- netty框架 服务器连接客户端以后,怎么先发送数据给客户端再读取客户端的数据
- 求助一个数据库字段的设计,请教如何【注解】此字段
- struts2 action方法返回原页面
//加上num天
long time = date.getTime() + num*86400000;
date.setTime(time);
return dateformat2.format(date);
}
private static SimpleDateFormat dateformat2 = new SimpleDateFormat("yyyy-MM-dd");
很简单
int now=c.get(Calendar.DAY_OF_WEEK);
int temp=5;//周日是0,所以周四是5
c.add(Calendar.DATE, temp-now);
System.out.println(new SimpleDateFormat("yyyy-MM-dd").forma(c.getTime()));
周日到周六是1-7 周日是1 不是0 不过处理的时候你要注意你的周日是要怎么处理,你的周日是算一周的开始是是算一周的结束,Calendar中周日是算一周的开始的,如果你的周日是算一周的结束要判断下
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar calendar = Calendar.getInstance();
calendar.setTime(dateFormat.parse("2012-03-18"));
int week = calendar.get(Calendar.DAY_OF_WEEK);
if(week == 1) {//周日
calendar.add(Calendar.DAY_OF_MONTH, -3);
} else {
calendar.add(Calendar.DAY_OF_MONTH, 5 - week);
}
System.out.println(dateFormat.format(calendar.getTime()));
System.out.println(calendar.get(Calendar.DAY_OF_WEEK));