java 8 Instant.now() 显示错误的即时时间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38305465/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java 8 Instant.now() is showing wrong instant time
提问by optional
In Java 8 Instant.now()
method showing wrong time .
My code looks like :
在 Java 8Instant.now()
方法中显示错误的时间。我的代码看起来像:
import java.time.*;
import java.time.temporal.*;
public class DateTimeDemo{
public static void main(String []args){
Instant now = Instant.now();
System.out.println(now);
}
}
Its date part is correct but time part .
它的日期部分是正确的,但时间部分是正确的。
eg
例如
2016-07-11T11:01:25.498Z but in my system it is 4.31 PM
2016-07-11T11:01:25.498Z 但在我的系统中是 4.31 PM
I am using Asia/Calcutta TimeZone
我正在使用亚洲/加尔各答时区
回答by Jon Skeet
That's the correct time. Note the "Z" at the end, indicating UTC- 11:01:25 in UTC is 16:31:25 in Asia/Calcutta.
那是正确的时间。请注意末尾的“Z”,表示UTC- UTC 中的 11:01:25 是亚洲/加尔各答的 16:31:25。
If you want to represent "now" in your default time zone, use ZonedDateTime.now()
instead.
如果要在默认时区中表示“现在”,请ZonedDateTime.now()
改用。