Jared Smith Jared Smith - 1 year ago 138
Java Question

How to change the deafult epoch of 1970-01-01T00:00:00Z for LocalDataTime

thanks for taking the time to help.

In the LocalDataTime class there is a method to convert epoch second and nano second to UTC time.

It looks like:

LocalDateTime dateTime = LocalDateTime.ofEpochSecond()

However it Obtains an instance of LocalDateTime using seconds from the epoch of 1970-01-01T00:00:00Z.

Is there a way to modify 1970 to 1980 as default instance?

Here is more info about the LocalDataTime class:


I believe I need it to be changed since:

epoch seconds = 667662644
epoch nanoseconds = 1165598

should come out to:

13:50:44.001165598 03/03/2001

but I am getting:

13:50:44.001165598 2/27/1991

Any tips would be much appreciated.

Answer Source

Figure out the offset you need and add it to all the epoch seconds values before converting to a `LocalDateTime'.

The offset can be calculated once and then hard-coded as

public static final int EPOCH_OFFSET = nnnn;


    Instant GPS = Instant.parse("1980-01-06T00:00:00Z");
    long    GPS_EPOCH = GPS.toEpochMilli();
    System.out.printf("%s %,d\n",GPS.toString(), GPS_EPOCH);


1980-01-06T00:00:00Z 315,964,800,000
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download