Today, the ability to upload files, and to record the current time as the upload time, but found in the Java New Date () and the time after the format problem, can not be stored in the database, for example:
Today is July 31, 2014, the time is 6:51 P.M. 42 seconds, but the output is 2014-51-31 06:51:42, first of all, the month is certainly wrong, and secondly, 6 o'clock in the afternoon best can be shown as 18 points.
Don't know where the problem is, check the format date identifier:
Dateutils.asstring (New Date (), "Yyyy-mm-dd Hh:mm:ss")
Then Baidu a bit, found the problem:
Month with the "MM" actually represents the minutes, not the month, the month to use "MM", and to use the 24-hour system is "HH", "HH" is a 12-hour system.
The specific rules are as follows:
[plain] view Plain copy time date identifier: yyyy: Year MM: Month DD: Day hh:1~12 Hour System (1-12) [plain] view plain copy HH:24-hour System (0-23) mm: Divided ss: sec S: Milliseconds E: Days of the week D: Day of the Year F: the first few weeks of the January (will divide the total number of days in this month by 7) W: The first few weeks of the year W: The Week of January (depending on the actual situation To calculate) A: The last afternoon logo K: and HH Almost, said 24 hours a day system (1-24). K: And Hh<span style= "font-family:arial, Helvetica, Sans-serif;" > Almost </span><span style= "font-family:arial, Helvetica, Sans-serif;" That means 12 hours a day (0-11). </span> Z: Indicates time zone
Summary: The date operation is often used, but has not been very skilled grasp, the note is not enough attention.