Convert millisecond String to Date in Java

后端 未结 4 1060
走了就别回头了
走了就别回头了 2020-12-01 23:43

i have a String x = \"1086073200000\" . This is basically millisecond which I need to convert to a Date.

To convert i am using

DateFormat formatter          


        
4条回答
  •  孤城傲影
    2020-12-02 00:32

    I tried this code and it worked for me

    public static void main(String[] args) {
        String x = "1086073200000";
        long foo = Long.parseLong(x);
        System.out.println(x + "\n" + foo);
    
        Date date = new Date(foo);
        DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
        System.out.println(formatter.format(date)); 
    }
    

提交回复
热议问题