我正在尝试将 withWeekOfWeekyear 转换为 java.time。我似乎无法弄清楚为什么 withWeekOfWeekyear 与 weekOfWeekBasedYear 得到不同的偏移量。
DateTime dateTimeWeek = new DateTime().withWeekOfWeekyear(1);
OffsetDateTime offsetDateTimeWeek = OffsetDateTime.now().with(WeekFields.ISO.weekOfWeekBasedYear(), 1);
DateTime dateTime = new DateTime();
OffsetDateTime offsetDateTime = OffsetDateTime.now();
System.out.println(dateTimeWeek); // 2016-01-04T12:20:50.981-05:00
System.out.println(offsetDateTimeWeek); // 2016-01-04T12:20:51.034-04:00
System.out.println(dateTime); // 2016-07-18T12:20:51.101-04:00
System.out.println(offsetDateTime); // 2016-07-18T12:20:51.101-04:00
最佳答案
org.joda.time.DateTime
具有时区意识。
A
DateTime
calculates its fields with respect to atime zone
.
java.time.OffsetDateTime
不时区感知,即不调整夏令时。
OffsetDateTime
adds to the instant the offset from UTC/Greenwich, which allows the local date-time to be obtained.ZonedDateTime
adds full time-zone rules.
java.time.ZonedDateTime
时区感知,所以如果你使用它,你应该得到相同的结果。
ZonedDateTime
is an immutable representation of a date-time with a time-zone.
关于java - 为什么 withWeekOfWeekyear 给我不同的偏移量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38441828/