Milliseconds to Date in GMT in Java

后端 未结 5 843
一个人的身影
一个人的身影 2020-12-06 08:19

I need to covert milliseconds to GMT date (in Android app), example:

1372916493000

When I convert it by this code:

Calendar cal          


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-06 08:59

    If result which looks incorrect means System.out.println(date) then it's no surprise, because Date.toString converts date into string representation in local timezone. To see result in GMT you can use this

    SimpleDateFormat df = new SimpleDateFormat("hh:ss MM/dd/yyyy");
    df.setTimeZone(TimeZone.getTimeZone("GMT"));
    String result = df.format(millis);
    

提交回复
热议问题