How to remove milliseconds from Date Object format in Java

前端 未结 8 955
夕颜
夕颜 2020-12-15 21:56

Since the java.util.Date object stores Date as 2014-01-24 17:33:47.214, but I want the Date format as 2014-01-24 17:33:47. I w

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-15 22:43

    You can use the SimpleDateFormat class to format the date as necessary. Due to the diversity of possible combinations, I will simply include the documentation link here:

    http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

    Your code will look something similar to the following:

    System.out.println(new SimpleDateFormat("MM/dd/yyyy").format(date));
    

提交回复
热议问题