Search code examples
javascalatimeutc

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


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


Solution

  • This is what I am doing

    I am using Joda-Time and doing

    DateTimeZone.setDefault(DateTimeZone.UTC);
    DateTime.now.toString
    

    On client I see it as

    Wed, 02 Sep 2015 20:57:34 GMT
    

    and on server I see it as

    2015-09-02T20:24:43.594Z
    

    P.S. Don't compare values, they are copied differently, the format is what I wanted to share