【发布时间】:2016-01-30 08:32:30
【问题描述】:
给定一个FileTime fileTime,如何以自定义方式将其格式化为字符串?
String s = fileTime.toString() 仅以 ISO 格式提供。
String s = DateTimeFormatter.ofPattern("uuuu-MMM-dd HH:mm:ss")
.format(fileTime.toInstant());
抛出UnsupportedTemporalTypeException: Unsupported field: Year
【问题讨论】:
-
你的意思是
yyyy而不是uuuu -
@Kal 我都试过了。
yyyy只是抛出Unsupported field: Year of Era而不是Unsupported field: Year。 -
你试过
toMillis而不是toInstant吗?格式化Instant需要时区。 -
@Kal 我试过this。如何处理
toMillis的结果? -
啊是的。我认为您最好的选择是将时区附加到 DateTimeFormatter -- stackoverflow.com/questions/25229124/format-instant-to-string
标签: java date-formatting java-time