Difference between date formatting {0:yyyy-mm-dd HH:mm:ss.fff} and {0:yyyy-mm-dd hh:mm:ss.fff}

Source: Internet
Author: User

Original: The 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 is -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 MMMM es-mx GMT Abril
dddd MMMM yy gg en-US GMT Thursday April A.D.
dddd MMMM yy gg es-mx GMT jueves Abril
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

Difference between date formatting {0:yyyy-mm-dd HH:mm:ss.fff} and {0:yyyy-mm-dd hh:mm:ss.fff}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.