long timestamp to LocalDateTime

We Are Going To Discuss About long timestamp to LocalDateTime. So lets Start this Java Article.

long timestamp to LocalDateTime

Advertisements
  1. long timestamp to LocalDateTime

    If you are using the Android threeten back port then the line you want is this
    LocalDateTime.ofInstant(Instant.ofEpochMilli(startTime), ZoneId.systemDefault())

  2. long timestamp to LocalDateTime

    If you are using the Android threeten back port then the line you want is this
    LocalDateTime.ofInstant(Instant.ofEpochMilli(startTime), ZoneId.systemDefault())

Solution 1

Advertisements

You need to pass timestamp in milliseconds:

long test_timestamp = 1499070300000L;
LocalDateTime triggerTime =
        LocalDateTime.ofInstant(Instant.ofEpochMilli(test_timestamp), 
                                TimeZone.getDefault().toZoneId());  

System.out.println(triggerTime);

Result:

2017-07-03T10:25

Or use ofEpochSecond instead:

long test_timestamp = 1499070300L;
LocalDateTime triggerTime =
       LocalDateTime.ofInstant(Instant.ofEpochSecond(test_timestamp),
                               TimeZone.getDefault().toZoneId());   

System.out.println(triggerTime);

Result:

2017-07-03T10:25

Original Author Juan Of This Content

Solution 2

Advertisements

Try with the following..

long test_timestamp = 1499070300000L;
    LocalDateTime triggerTime =
            LocalDateTime.ofInstant(Instant.ofEpochMilli(test_timestamp), TimeZone
                    .getDefault().toZoneId());  

By default 1499070300000 is int if it dosen’t contain l in end.Also pass time in milliseconds.

Original Author Akshay Of This Content

Solution 3

Advertisements

If you are using the Android threeten back port then the line you want is this

LocalDateTime.ofInstant(Instant.ofEpochMilli(startTime), ZoneId.systemDefault())

Original Author JamieH Of This Content

Solution 4

Advertisements

Try with Instant.ofEpochMilli() or Instant.ofEpochSecond() method with it-

long test_timestamp = 1499070300L;
LocalDateTime date =
    LocalDateTime.ofInstant(Instant.ofEpochMilli(test_timestamp ), TimeZone
        .getDefault().toZoneId());

Original Author Razib Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment