Converting from Milliseconds to UTC Time in Java

后端 未结 3 695
粉色の甜心
粉色の甜心 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条回答
  •  执笔经年
    2021-01-01 21:14

    Try below..

    package com.example;
    
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.TimeZone;
    
    public class TestClient {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            long time = 1427723278405L;
            SimpleDateFormat sdf = new SimpleDateFormat();
            sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
            System.out.println(sdf.format(new Date(time)));
    
        }
    
    }
    

提交回复
热议问题