[英]How to convert date in milliseconds to localDate?
I'm trying to convert date Long 1581420629955L
to LocalDate and then revert that.我正在尝试将日期 Long 1581420629955L
转换为 LocalDate 然后将其还原。
To transform it in localDate, i use:要在 localDate 中转换它,我使用:
final LocalDate localDate = Instant.ofEpochMilli(1581420629955L).atZone(ZoneId.of("UTC")).toLocalDate();
My localDate
value is good => 2020-02-11
我的localDate
值很好 => 2020-02-11
And Then, i revert that with:然后,我将其还原为:
final GregorianCalendar cal = new GregorianCalendar(localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth());
final Long cal.setTimeZone(TimeZone.getTimeZone("UTC"));
final Long timeMilli = cal.getTimeInMillis();
But my timeMilli
is not equals to 1581420629955
.但我的timeMilli
不等于1581420629955
。 :( :(
How can i do that?我怎样才能做到这一点?
Thanks:D感谢:D
According to OH GOD SPIDERS, i finally use localDate.atStartOfDay().toInstant(ZoneOffset.UTC).toEpochMilli()
that solve my problem:D根据 OH GOD SPIDERS,我终于使用localDate.atStartOfDay().toInstant(ZoneOffset.UTC).toEpochMilli()
来解决我的问题:D
Thanks for all yours responses !感谢您的所有回复!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.