Convert millisecond String to Date in Java

后端 未结 4 1059
走了就别回头了
走了就别回头了 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条回答
  •  猫巷女王i
    2020-12-02 00:35

    double tempo=Double.parseDouble(z);
    

    Why are you parsing your String which is supposed to be a Long as a Double?

    Try using Long.parseLong:

    String x = "1086073200000"
    
    DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    
    long milliSeconds= Long.parseLong(x);
    System.out.println(milliSeconds);
    
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(milliSeconds);
    System.out.println(formatter.format(calendar.getTime())); 
    

提交回复
热议问题