使用Java中的DateFormatter获取UTC时间。

huangapple go评论71阅读模式
英文:

Get UTC time with DateFormatter in java

问题

我正在尝试使用DateFormatter检索UTC时间HH:MM:SS。我似乎找不到一个简单的示例。理想情况下,我想做类似以下的事情:

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH,mm,ss").withLocale(TimeZone.getTimeZone("UTC"));

但是这段代码不起作用。有人可以帮助我找到一个简单的方法吗?

英文:

I am trying to retrieve UTC time HH:MM:SS using DateFormatter. I can't seem to find a simple example. Ideally, I'd like to do something like:

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH,mm,ss").withLocale(TimeZone.getTimeZone("UTC"));

but this code doesn't work. Can someone help me find an easy way to do this?

答案1

得分: 0

不知道zoneIds。可以使用以下方法完成:

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH,mm,ss").withZone(ZoneId.of("UTC"));
英文:

Didn't know about zoneIds. It can be done with this:

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH,mm,ss").withZone(ZoneId.of("UTC"));

huangapple
  • 本文由 发表于 2020年7月29日 23:32:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/63157154.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定