在尝试将java.util.Date
转换为java.time.LocalDate
时,我遇到了以下异常。
java.time.DateTimeException: Unable to obtain ZonedDateTime from TemporalAccessor: 2014-08-19T05:28:16.768Z of type java.time.Instant
代码如下:public static Date getNearestQuarterStartDate(Date calculateFromDate){
int[] quaterStartMonths={1,4,7,10};
Date startDate=null;
ZonedDateTime d=ZonedDateTime.from(calculateFromDate.toInstant());
int frmDateMonth=d.getMonth().getValue();
我使用 ZonedDateTime
类的方式有问题吗?根据文档,它应该能将 java.util.Date
对象转换为 ZonedDateTime
。上面的日期格式是标准日期格式吗?如果不行,我需要退回使用Joda time吗?如果有人能提供一些建议,那就太好了。
Date
类型与Instant
类型类似,它们都是 UNIX 时间戳。此外,通常惯例认为 UNIX 时间戳是 UTC 时区时间。 - kevinarpe