Difference between date formatting {0:yyyy-mm-dd HH:mm:ss.fff} and {0:yyyy-mm-dd hh:mm:ss.fff}
{0:YYYY-MM-DD HH:MM:SS.FFF}: Date formatted with 24-hour format
{0:YYYY-MM-DD HH:MM:SS.FFF}: Date formatted with 12-hour format
The following is the same, from left to right-year-month-day time: minute: seconds. milliseconds
{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
---assumed time was-2009-03-17 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 2009-03-17 16:50:49.920
String LastUpdate3 = ObjValue2 = = null? String. Empty:string. Format ("{0:yyyy-mm-dd hh:mm:ss.fff}", objValue2); --Output 2009-03-17 04:50:49.920
//--------------------
Y Displays the year portion of the specified DateTime object as a number with a maximum number of two digits. Ignores the first two digits of the year. If the year is a number (1-9), it is displayed as a single digit.
YY Displays the year portion of the specified DateTime object as a number with a maximum number of two digits. Ignores the first two digits of the year. If the year is a single number (1-9), it is formatted with a leading 0 (01-09).
YYYY Displays the year part (including century) for the specified DateTime object. If the year length is less than four bits, append 0 to the front as needed to make the displayed year four bits.
Z Displays the time zone offset for the current time zone of the system, in units of full hours only. The offset is always displayed as a leading or trailing symbol (0 is displayed as "+0"), indicating a number of hours earlier than Greenwich Mean Time (+) or after Greenwich Mean Time (-). The range of values is –12 to +13. If the offset is a single digit (0-9), it is displayed as a single number with the appropriate leading symbol. The setting for this time zone is specified as +x or –X, where X is the offset relative to GMT in hours. The offset shown is influenced by the summer time system.
ZZ Displays the time zone offset for the current time zone of the system in units of the entire hour only. The offset is always displayed as a leading or trailing symbol (0 is displayed as "+00"), indicating a number of hours earlier than Greenwich Mean Time (+) or after Greenwich Mean Time (-). The value range is –12 to +13. If the offset is a single number (0-9), it is formatted as preceded with 0 (01-09) with the appropriate leading symbol. The setting for this time zone is specified as +x or –X, where X is the offset relative to GMT in hours. The offset shown is influenced by the summer time system.
ZZZ, zzz (plus any number of additional "Z" characters) displays the time zone offset of the system's current time zone in hours and minutes. Offsets are always displayed with leading or trailing symbols (0 shown as "+00:00"), indicating hours and minutes earlier than Greenwich Mean Time (+) or Greenwich Mean Time (-). The value range is –12 to +13. If the offset is a single number (0-9), it is formatted as preceded with 0 (01-09) with the appropriate leading symbol. The setting for this time zone is specified as +x or –X, where X is the offset relative to GMT in hours. The offset shown is influenced by the summer time system.
: Time separator.
/Date separator.
"Quoted string. Displays the literal value of any string between two quotation marks after the escape character (/).
' Quoted string. Displays the text value of any string between two "'" characters.
%c where c is a standard format character that displays the standard format pattern associated with the format character.
\c where c is any character, the escape character displays the next one as text. In this context, the escape character cannot be used to create an escape sequence, such as "\ n" for a newline.
Any other character other characters are written directly to the output string as text.
When you pass a custom pattern to datetime.tostring, the pattern must be at least two characters in length. If only "D" is passed, the common language runtime interprets it as a standard format specifier, because all individual format specifiers are interpreted as standard format specifiers. If you pass a single "H", an exception is thrown because there is no standard "h" format specifier. To format only with a single custom format, add a space before or after the specifier. 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 (the value shows the current time). The different culture and time zone settings are given in the example to illustrate the effect of changing the culture. You can change the current culture by changing the values in the Date/Time Control Panel in Microsoft Windows, passing your own DateTimeFormatInfo object, or passing the CultureInfo object settings to a different culture. This table is a quick guide that explains how custom date and time specifiers affect formatting. See the sample Code section below that illustrates these specifiers.
format specifier current culture time zone output
d, M en-US GMT, 4
d, M es-mx GMT, 4
d MMMM en-US GMT (April)
d MMM M es-mx GMT Abril
dddd MMMM yy gg en-US GMT Thursday April A.D.
DDDD MMMM yy gg es-mx GMT jueves Abril 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 G MT +10
hh:mm, g\mt zzz en-US GMT 05:13 GMT +00:00
Difference between date formatting {0:yyyy-mm-dd HH:mm:ss.fff} and {0:yyyy-mm-dd hh:mm:ss.fff}