The meaning of the date and time format string "yyyy-MM-dd HH:mm:ss"

yyyy-MM-dd HH:mm:ss
  • "yyyy": Indicates a four-digit year, for example: 2022.
  • "MM": Indicates the two-digit month, from 01 to 12.
  • "dd": represents a two-digit date, from 01 to 31.
  • "HH": Indicates the number of hours in the 24-hour clock, from 00 to 23.
  • "mm": indicates the number of minutes, from 00 to 59.
  • "ss": indicates the number of seconds, from 00 to 59.

In datetime format strings, use uppercase "YYYY" to represent a four-digit year. This is the same as lowercase "yyyy", indicating the year part. The difference between the two is that "YYYY" is based on the ISO week-based year, while "yyyy" is based on the standard Gregorian calendar year. In most cases, using "yyyy" is the more common and recommended way to represent the year.

Used to avoid confusion with "MM" (meaning month). Therefore, to express minutes, use lowercase "mm".

In the date and time format string, use lowercase "dd" to represent a two-digit date, ranging from 01 to 31. This represents the day part of the month. Note that unlike the capital "DD", "dd" represents an actual date, whereas "DD" represents the day of the year. Therefore, it is common and recommended to use lowercase "dd" to represent dates in datetime format strings.

In datetime format strings, use uppercase "SS" to represent two-digit milliseconds. This represents the millisecond portion of time.
However, it is important to note that most common datetime libraries and formatting methods typically use lowercase "ss" to represent seconds, not milliseconds.
Therefore, in general, using lowercase "ss" to represent seconds is the more common and recommended way.
If you need to express milliseconds, you can use lowercase "sss" to represent the three-digit number of milliseconds.

Guess you like

Origin blog.csdn.net/qq_41638851/article/details/132760199