0

I need a java function to convert 13 digit epoch utc time in milliseconds to Java Instant time in UTC. Can anyone please help?

input : 1611476543540
output : 2021-01-24 08:23:13

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Ann
  • 217
  • 1
  • 9
  • https://stackoverflow.com/questions/35183146/how-can-i-create-a-java-8-localdate-from-a-long-epoch-time-in-milliseconds may be a better dupe, if the aim is to get an `Instant`, rather than a `Date`. – Joe Jan 24 '21 at 08:31
  • `ZonedDateTime.ofInstant(Instant.ofEpochMilli(1611476543540L), ZoneId.of("UTC"))` (given as there are many differing variants). The ISO standard gives a T instead of blank, but there are predefined formats. – Joop Eggen Jan 24 '21 at 08:35
  • 2
    @JoopEggen - You need just `Instant.ofEpochMilli(1611476543540L)`. – Arvind Kumar Avinash Jan 24 '21 at 08:42
  • @LiveandLetLive also for formating with a different format?Probably. Aaah, everytime I do too much. – Joop Eggen Jan 24 '21 at 08:44
  • @JoopEggen - For formatting, *Yes, one needs to do it in your way but OP's requirement is just to get `Instant`*. – Arvind Kumar Avinash Jan 24 '21 at 08:47
  • 1
    Instant.ofEpochMilli(1611476543540L) worked for me. thanks Joop – Ann Jan 24 '21 at 08:52

0 Answers0