[英]why get the wrong week display name from unix timestamp in Java
现在我使用这个 Java 代码来获取周显示名称:
String dateTime = CustomDatetimeUtil.timeStamp2Date(response.getStatisticTime(), "yyyy-MM-dd");
response.setStatisticDate(dateTime);
String displayName = Instant.ofEpochSecond(response.getStatisticTime())
.atZone(ZoneId.of("Asia/Shanghai"))
.getDayOfWeek()
.getDisplayName(TextStyle.FULL, Locale.CHINA);
response.getStatisticTime()
值为1614783599999
。 但我得到的显示名称是· Sunday(星期日)
。 正确的值是星期三。 我应该怎么做才能获得正确的价值?
您正在使用Instant.ofEpochSecond
-但是您获得的值足够大,以至于它可能是自 Unix epoch以来的毫秒数,而不是seconds数。
所以基本上你需要使用Instant.ofEpochMilli
来代替。
我建议将来也使用Epoch Converter站点——它允许您输入一个数值,它会向您显示该值的含义,包括它在执行转换时采用的单位。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.