Date Format {0: yyyy-mm-dd hh: mm: Ss. fff} and {0: yyyy-mm-dd hh: mm: Ss. fff} difference {0: yyyy-mm-dd hh: mm: Ss. fff}: format the date in the 24-hour format.
{0: yyyy-mm-dd hh: mm: Ss. fff}: format the date in 12-hour format.
Similarly, from left to right is-Year-month-day: minute: Second. millisecond
{0: yyyy-mm-dd hh: mm: ss zzz}
{0: yyyy-mm-dd hh: mm: Ss. ff zzz}
{0: yyyy-mm-dd hh: mm: Ss. fff ZZZ}
{0: yyyy-mm-dd hh: mm: Ss. ffff zzz}
The following test code
// --- Assume the time is-16:50:49. 92
Object objvalue2 = business. Services. executescalar (sqliteconnstring, "select lastupdate from cmitemclass2 order by lastupdate DESC limit 0, 1 ");
String lastupdate2 = objvalue2 = NULL? String. Empty: String. Format ("{0: yyyy-mm-dd hh: mm: Ss. fff}", objvalue2); // -- output 16:50:49. 920
String lastupdate3 = objvalue2 = NULL? String. Empty: String. Format ("{0: yyyy-mm-dd hh: mm: Ss. fff}", objvalue2); // -- output 04:50:49. 920
//--------------------
Y displays the year of the specified datetime object as a number with a maximum of two digits. Ignore the first two digits of the year. If the year is a digit (1-9), it is displayed as a digit.
YY displays the year of the specified datetime object as a number with a maximum of two digits. Ignore the first two digits of the year. If the year is a digit (1-9), format it with a leading 0 (01-09 ).
Yyyy displays the year (including Century) of the specified datetime object ). If the length of a year is less than four digits, add zero to the beginning to increase the length of the year to four digits.
Z only displays the time zone offset of the current time zone of the system in units of the hour. The total offset is displayed with a leading or trailing sign (0 is displayed as "+ 0"), indicating the hours earlier than Greenwich Mean Time (+) or later than Greenwich Mean Time. The value range is-12 to + 13. If the offset is a single digit (0-9), it is displayed as a single digit with a proper leading symbol. This time zone is set to + X or-X, where X is the offset relative to GMT in hours. The displayed offset is affected by the daylight saving time.
ZZ only displays the time zone offset of the current time zone of the system in units of the hour. The total offset is displayed with a leading or trailing sign (0 is displayed as "+ 00"), indicating the hours earlier than Greenwich Mean Time (+) or later than Greenwich Mean Time. The value range is-12 to + 13. If the offset is a single number (0-9), format it to the front with 0 (01-09) and a proper leading symbol. This time zone is set to + X or-X, where X is the offset relative to GMT in hours. The displayed offset is affected by the daylight saving time.
Zzz and ZZZ (plus any number of additional "Z" characters) display the time zone offset of the system's current time zone in units of hours and minutes. The offset is always displayed with a leading or trailing sign (0 is displayed as "+ 00:00"), indicating the hours and minutes earlier than Greenwich Mean Time (+) or later than Greenwich Mean Time. The value range is-12 to + 13. If the offset is a single number (0-9), format it to the front with 0 (01-09) and a proper leading symbol. This time zone is set to + X or-X, where X is the offset relative to GMT in hours. The displayed offset is affected by the daylight saving time.
: Time separator.
/Date separator.
"String with quotation marks. Displays the text value of any string between two quotation marks after the escape character.
'String with quotation marks. Displays the text value of any string between two "'" characters.
% C, where C is a standard character, displays the Standard Format mode associated with the format character.
\ C contains any character, and the Escape Character displays the next character as text. In this context, the escape character cannot be used to create an escape sequence (for example, "\ n" indicates a line break ).
Other characters can be directly written to the output string as text.
When you pass the custom mode to datetime. tostring, the mode must be at least two characters long. If only "D" is passed, the common language runtime interprets it as a standard format specifier because all single format specifiers are interpreted as standard format specifiers. If a single "H" is passed, an exception is thrown because there is no standard "H" format specifier. To format only a single custom format, add a space before or after the description. For example, the format string "H" is interpreted as a custom format string.
The following table shows an example of using any value datetime. Now (this value shows the current time. The example provides different settings for the region and time zone to illustrate the impact of changing the region. You can change the current culture by changing the value in the date/time control panel of Microsoft Windows, passing your own datetimeformatinfo object, or passing the settings of the cultureinfo object to different cultures. This table is a quick guide to how custom Date and Time specifiers affect formatting. See the sample code that explains these specifiers below this table.
Format description: output of the current regional Time Zone
D, m en-us gmt 12, 4
D, m es-mx GMT 12, 4
D mmmm en-us gmt 12 w.l
D mmmm es-mx GMT 12 Abril
Dddd mmmm YY Gg en-us gmt Thursday limit L 01 A.D.
Dddd mmmm YY Gg es-mx GMT jueves Abril 01 DC
H, M: s en-us gmt 6, 13: 12
HH, MM: SS en-us gmt 06,13: 12
Hh-mm-SS-TT en-us gmt 06-13-12-AM
Hh: Mm, G \ Mt Z en-us gmt 05:13 GMT + 0
Hh: Mm, G \ Mt Z en-us gmt + 10: 00 05:13 GMT + 10
Hh: Mm, G \ Mt ZZZ en-us gmt 05:13 GMT + 00:00
From: http://www.cnblogs.com/jhxk/articles/1618194.html