Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to I convert long (currentTimeInMillis) to UTC timestamp?

Tags:

java

time

utc

scala

My client is sending me Long which could be thought as

scala> System.currentTimeMillis
res3: Long = 1441056836609

scala> 

How do I convert that into UTC timeStamp?

On Server, we are using Java 8

like image 227
daydreamer Avatar asked Aug 31 '15 21:08

daydreamer


1 Answers

You can use the Instant class methods.

import java.time.Instant;
import java.time.ZoneOffset;

Instant.ofEpochMilli(<yourmillis>).atOffset(ZoneOffset.UTC).toString();

Your example date would be "2015-08-31T21:33:56.609Z".

like image 114
Bilk Avatar answered Nov 15 '22 08:11

Bilk