Java date is not preserving milliseconds in conversion with simple date format

前端 未结 5 1641
死守一世寂寞
死守一世寂寞 2021-01-19 01:32

I\'m trying to convert the following string \"2012-04-13 04:08:42.794\" to a date type:

    SimpleDateFormat dateFormat = new SimpleDateFormat(\         


        
5条回答
  •  醉梦人生
    2021-01-19 02:08

    He's my go at it (trying to keep the same code style as yours) :

    import java.util.*;
    import java.text.*;
    public class main {
     public static void main(String[] args)throws Exception {
     long yourmilliseconds = 1119193190;
    SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm:ss.SSS");
    
    Date resultdate = new Date(yourmilliseconds);
    System.out.println(sdf.format(resultdate));  } 
    }  
    

    Output :

    Jan 13,1970 17:53:13.190
    

    Regards, Erwald

提交回复
热议问题