Java日期格式很奇怪

Kar*_*son 0 java date

我有一个问题,我希望得到一天的开始,但它似乎是通过自动设置为12:00.

SimpleDateFormat dfFull = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String todayDate = dfFull.parse("2014-06-06 00:00:00");

today = dfFull.format(todayDate);
System.out.println(today);
Run Code Online (Sandbox Code Playgroud)

为什么会吐出来:

2014-06-06 12:00:00
Run Code Online (Sandbox Code Playgroud)

12:00:00是问题所在

Sud*_*hul 11

那是因为hh以12小时格式表示小时.你需要HH改用.

SimpleDateFormat dfFull = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请查看文档.

另外,在旁注中,代码中存在拼写错误.

SimpleDateFormat dfFull = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date todayDate = dfFull.parse("2014-06-06 00:00:00"); // todayDate must be of type Date and not String
String today = dfFull.format(todayDate); // today should be of type String
System.out.println(today);
Run Code Online (Sandbox Code Playgroud)