Converting from Milliseconds to UTC Time in Java

后端 未结 3 697
粉色の甜心
粉色の甜心 2021-01-01 20:30

I\'m trying to convert a millisecond time (milliseconds since Jan 1 1970) to a time in UTC in Java. I\'ve seen a lot of other questions that utilize SimpleDateFormat to chan

3条回答
  •  -上瘾入骨i
    2021-01-01 21:25

    You May check this..

    Calendar calendar = new GregorianCalendar();
        calendar.setTimeInMillis(1427723278405L);
    
        DateFormat formatter = new SimpleDateFormat("dd MMM yyyy HH:mm:ss z");
    
        formatter.setCalendar(calendar);
    
        System.out.println(formatter.format(calendar.getTime()));
    
        formatter.setTimeZone(TimeZone.getTimeZone("America/New_York"));
    
        System.out.println(formatter.format(calendar.getTime()));
    

提交回复
热议问题