Java 计算日期加、减一天
作者:
XM_Dong | 来源:发表于
2018-05-08 17:43 被阅读137次public static void main(String[] args)
throws ParseException
{
SimpleDateFormat sj = new SimpleDateFormat("yyyy-MM-dd");
String today = "2015-11-30";
Date d = sj.parse(today);
Calendar calendar = Calendar.getInstance();
calendar.setTime(d);
calendar.add(Calendar.DATE, 1);
System.out.println("明天:" + sj.format(calendar.getTime()));
//此时日期变为2015-12-01 ,所以下面的-2,
//理论上讲应该是2015-11-29
calendar.add(calendar.DATE, -2);
System.out.println("前天:" + sj.format(calendar.getTime()));
}
本文标题:Java 计算日期加、减一天
本文链接:https://www.haomeiwen.com/subject/sjuwrftx.html
网友评论