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

前端 未结 5 1645
死守一世寂寞
死守一世寂寞 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:11

    The convertedDate object does in fact contain the millisecond information. The issue here is that the toString() method format does not print milliseconds.

    Do

     System.out.println(" in utils: " + dateFormat.format(convertedDate));
    

    You can also check if the ms are set with

     System.out.println("millis: " + convertedDate.getTime());
    

提交回复
热议问题