-1

I have to convert the following time to UTC but I don't know what format the current time is in. How do I convert it to UTC using Java? Unknown format:

1561554154352 

It clear to me which or how to do it based on the Java Date documentation. https://docs.oracle.com/javase/8/docs/api/java/util/Date.html

sgoodman
  • 167
  • 8

2 Answers2

3

That isn't so much a Date as it is an offset to an epoch (specifically, the number of milliseconds since midnight January 1, 1970 UTC). To convert it to a date, pass that number to the date constructor. Like,

long epochTime = 1561554154352L;
System.out.println(new Date(epochTime));

Outputs

Wed Jun 26 09:02:34 EDT 2019
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
0

The following will get you from Zulu(UTC):

System.out.println("Current elapsed from epoch => " + System.currentTimeMillis());
System.out.println("Convereted to UTC =>" + Instant.ofEpochMilli(System.currentTimeMillis()).toString());
Jeff Stewart
  • 125
  • 5