我正在尝试将今天的日期格式化为“MM/dd/yyy HH:00”,其中分钟总是被清零。使用这种格式时,时间显示不正确:
LocalDate date = DateTime.now().withZone(DateTimeZone.forID("America/New_York")).toLocalDate();
String format = date.toString("MM/dd/yyyy HH:00");
logger.info(format);
输出
是否有使用 LocalDate
获取时间的不同方法?
最佳答案
来自 LocalDate
的 JavaDoc :
A date without a time-zone in the ISO-8601 calendar system, such as 2007-12-03.
和:
This class does not store or represent a time or time-zone. Instead, it is a description of the date, as used for birthdays. It cannot represent an instant on the time-line without additional information such as an offset or time-zone.
使用LocalDateTime相反。
关于java - 在 Java 中使用 LocalDate 时未通过的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36434521/