日期:2014-05-18  浏览次数:20783 次

在jsp中如何实现时间相加后转换为yyyy-mm-dd格式?
在jsp中如何实现时间相加后转换为yyyy-mm-dd格式?
我会把当前时间转转换为yyyy-mm-dd格式
代码为
Date nowTime=new Date(); 
SimpleDateFormat dateFm = new SimpleDateFormat("yyyy-MM-dd"); 
out.println(dateFm.format(nowTime)); 

我也会把当前时间加3天
代码为
Calendar c = Calendar.getInstance(); 
c.add(Calendar.DAY_OF_YEAR,3); 
out.println("三天后时间:" + c.getTime() + "");

请问怎样把加3天后的时间转换为yyyy-mm-dd格式呢?

------解决方案--------------------
Java code
out.print(dateFm.format(c.getTime())); // 继续使用你的格式化类就可以了!

------解决方案--------------------
Java code
Date nowTime = new Date();
SimpleDateFormat dateFm = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.setTime(nowTime); // 你这里的先赋值为当前时间
c.add(Calendar.DAY_OF_YEAR, 3);
out.println("三天后时间:" + dateFm.format(c.getTime()) + "");