我想在一个特定的日期上加上一天。我该怎么做呢?
Date dt = new Date();
现在我想在这个日期上加一天。
我想在一个特定的日期上加上一天。我该怎么做呢?
Date dt = new Date();
现在我想在这个日期上加一天。
当前回答
使用DateTime对象。加上任何你想要的时间等等。 希望这有用:)
其他回答
我更喜欢用joda来计算日期和时间,因为它可读性更好:
Date tomorrow = now().plusDays(1).toDate();
Or
endOfDay(now().plus(days(1))).toDate()
startOfDay(now().plus(days(1))).toDate()
这将使任何日期加1
String untildate="2011-10-08";//can take any date in current format
SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd" );
Calendar cal = Calendar.getInstance();
cal.setTime( dateFormat.parse(untildate));
cal.add( Calendar.DATE, 1 );
String convertedDate=dateFormat.format(cal.getTime());
System.out.println("Date increase by one.."+convertedDate);
我发现了一个简单的方法,可以向Date对象添加任意时间
Date d = new Date(new Date().getTime() + 86400000)
地点:
86 400 000 ms = 1 Day : 24*60*60*1000
3 600 000 ms = 1 Hour : 60*60*1000
你可以像这样尝试java.util.Date库-
int no_of_day_to_add = 1;
Date today = new Date();
Date tomorrow = new Date( today.getYear(), today.getMonth(), today.getDate() + no_of_day_to_add );
根据需要更改no_of_day_to_add的值。
我设置了no_of_day_to_add的值为1,因为你只想添加一天。
更多信息可以在本文档中找到。
使用DateTime对象。加上任何你想要的时间等等。 希望这有用:)