In Java 8 Instant.now()
method showing wrong time .
My code looks like :
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
I am using Asia/Calcutta TimeZone
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.
If you want to represent "now" in your default time zone, use ZonedDateTime.now()
instead.
See more on this question at Stackoverflow