减少垃圾是正确的方法。 日期: 1天。
我想像这样的东西。
Calendar cal = Calendar.getInstance();
cal.setTime(toDate);
cal.add(Calendar.DATE, 1);
toDate = cal.getTime();
这并不正确。
减少垃圾是正确的方法。 日期: 1天。
我想像这样的东西。
Calendar cal = Calendar.getInstance();
cal.setTime(toDate);
cal.add(Calendar.DATE, 1);
toDate = cal.getTime();
这并不正确。
这将发挥作用。
这并不正确。
如果是两人均欢迎 Java日报标:-
如果你不喜欢托尼·恩尼斯解决办法中的数学
Date someDate = new Date(); // Or whatever
Date dayAfter = new Date(someDate.getTime() + TimeUnit.DAYS.toMillis( 1 ));
但是,自发现这一Q/A以来,我越来越多地使用,而最近又转向 Java8(inspired)的新时代。 Joda, 感谢@BasilBourqueless, 指出这一点。
在 Java8,几乎所有时间级都采用.plusDays()方法,使这项任务变得微不足道:
LocalDateTime.now() .plusDays(1);
LocalDate.now() .plusDays(1);
ZonedDateTime.now() .plusDays(1);
Duration.ofDays(1) .plusDays(1);
Period.ofYears(1) .plusDays(1);
OffsetTime.now() .plus(1, ChronoUnit.DAYS);
OffsetDateTime.now() .plus(1, ChronoUnit.DAYS);
Instant.now() .plus(1, ChronoUnit.DAYS);
Java8还增加了在(现在)遗产日期和日历等与新的日间班之间开展互动的班级和方法,这些班级肯定是所有新发展的最佳选择。
Yeah, 这一权利。 Java 短信常常会错失。 我建议你尝试。 就像:
DateTime startDate = ...
DateTime endDate = startDate.plusDays(1);
或
Instant start = ...
Instant end = start.plus(Days.days(1).toStandardDuration());
这里我如何做:
Date someDate = new Date(); // Or whatever
Date dayAfter = new Date(someDate.getTime()+(24*60*60*1000));
最终的数学将每天的二分之一转换为零二。
If8或Joda 时间不是选择,你总是可以选择阿帕奇日期:
DateUtils.addDays(myDate, 1);
我认为,joda / 图书馆更清洁地工作日期。
Date thisDate = new Date(System.currentTimeMillis());
Date dayAfter = new Date(thisDate.getTime() + TimeUnit.DAYS.toMillis( 1 ));
Date dayBefore = new Date(thisDate.getTime() + TimeUnit.DAYS.toMillis( -1 ));
我是现代的回答。
......
我的建议是,它为什么不感到正确,是因为它如此ver。 增加一天,从概念上讲是一件简单的事情,在你的方案中应该有简单的代表。 这里的问题是<代码>Calendar类别设计不好:在使用时,你的代码必须是这样。 您是正确的:请
LocalDate toDate = LocalDate.of(2020, Month.FEBRUARY, 28);
LocalDate nextDate = toDate.plusDays(1);
System.out.println("Incremented date is " + nextDate);
产出是:
日期:2020-02-29
如果您的需要不同于<代码> 当地编码<>/代码>,则其他 j。 如Ivin的答复所示,时间班也采用<代码>plusDays方法。
<><><>>>>>
Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...
Check this, List<String> list = new ArrayList<String>(); for (int i = 0; i < 10000; i++) { String value = (""+UUID.randomUUID().getLeastSignificantBits()).substring(3, ...
I am in the middle of solving a problem where I think it s best suited for a decorator and a state pattern. The high level setting is something like a sandwich maker and dispenser, where I have a set ...
I have been trying to execute a MS SQL Server stored procedure via JDBC today and have been unsuccessful thus far. The stored procedure has 1 input and 1 output parameter. With every combination I ...
I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...
If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...
I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....
I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...