We Are Going To Discuss About long timestamp to LocalDateTime. So lets Start this Java Article.
long timestamp to LocalDateTime
- 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())
- 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
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
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
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
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.