我得到以下异常而试图转换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时间回退吗?
如果有人可以提供一些建议,那就太好了。
要将a转换Instant
为a ZonedDateTime
,ZonedDateTime
提供方法ZonedDateTime.ofInstant(Instant, ZoneId)
。所以
因此,假设您要使用ZonedDateTime
默认时区,则您的代码应为
ZonedDateTime d = ZonedDateTime.ofInstant(calculateFromDate.toInstant(),
ZoneId.systemDefault());
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句