首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

计算上一天

2012-09-01 
计算下一天已知今天日期,计算明天日期import java.text.SimpleDateFormatimport java.util.Datepublic c

计算下一天
已知今天日期,计算明天日期

import java.text.SimpleDateFormat;import java.util.Date;public class CalNextDate {public static void main(String[] args) {Date date = new Date();SimpleDateFormat sdf = new SimpleDateFormat("MMM. d, yyyy HH:mm:ss");        sdf.setTimeZone(java.util.TimeZone.getDefault());        System.out.println(sdf.format(getNextDate(date)));}private static Date getNextDate(Date date) {long addTime = 1;addTime *= 1;addTime *= 24;addTime *= 60;addTime *= 60;addTime *= 1000;Date d = new Date(date.getTime() + addTime);return d;}}
/** * 获取当前时间的后一天 * @param date * @return */public static Date getNextDay(Date date){Calendar cal = Calendar.getInstance();cal.setTime(date);cal.add(Calendar.DAY_OF_MONTH, 1);return cal.getTime();}/** * 获取当前时间的后一天 * @param date * @return */public static Date getNextDay(Date date){Calendar cal = Calendar.getInstance();cal.setTime(date);cal.add(Calendar.DAY_OF_MONTH, 1);return cal.getTime();}
不错,代码少多了。。。

热点排行