Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java 8 Instant.now() is showing wrong instant time

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

like image 675
optional Avatar asked Jul 11 '16 11:07

optional


Video Answer


1 Answers

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.

like image 66
Jon Skeet Avatar answered Sep 20 '22 13:09

Jon Skeet