Java的日期修改(如增加一天)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/q290994/article/details/81985298

最近用到了日期的添加与修改,下面一起学习:

import java.util.Date ;
     Date date=new   Date ();//取时间 
     Calendar calendar = new GregorianCalendar(); 
     calendar.setTime(date); 
     calendar.add(Calendar.DATE,1);//把日期往后增加一天.正数往后推,负数往前推 
     date=calendar.getTime();   //这个时间就是日期往后推一天的结果 

Calendar.DATECalendar.DAY_OF_MONTH 是一个意思,表示一个月中的一天。还有其他的表示分钟,小时等的字段

add(int field, int amount) 
Adds or subtracts the specified amount of time to the given calendar field, based on the calendar’s rules.

猜你喜欢

转载自blog.csdn.net/q290994/article/details/81985298
今日推荐