在我的机器上,当我调用 Instant.now
时,我得到以下信息:
scala> import java.time._
import java.time._
scala> Instant.now
res1: java.time.Instant = 2017-03-03T07:05:41.192Z
它返回秒的小数部分到千分之一,即 0.192Z。我只想将其返回到百位,因此在本例中为 0.19Z。我怎样才能做到这一点?
我尝试使用DateFormatter
,但当我将T
放入模式字符串中时,它就会崩溃。
最佳答案
您可以将 DateTimeFormatter
与您的自定义模式结合使用。
示例:
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SS'Z'")
.withZone(ZoneId.systemDefault())
.format(Instant.now());
关于java - 格式 UTC 日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42572761/