C # learning notes (2) time format strings,

Source: Internet
Author: User

C # learning notes (2) time format strings,

1. The fixed time formats output by the following four time formatting symbols should be the same in the settings of each region:

String in standard format Defined by the DateTimeFormatInfo. InvariantInfo attribute Custom Format String
"O" or "o" None Yyyy '-'mm'-'dd't'hh': 'mm': 'ss'. 'fffffffzz
"R" or "r" RFC1123Pattern Ddd, dd MMM yyyy HH ': 'mm': 'ss' gmt'
"S" SortableDateTimePattern Yyyy '-'mm'-'dd't'hh': 'mm': 'ss
"U" UniversalSortableDateTimePattern Yyyy '-'mm'-'dd hh': 'mm': 'ss 'Z'

 

 

 

 

 

 

 

2. Use the DateTimeFormatInfo. GetAllDateTimePatterns (char) function to obtain the custom format string corresponding to the standard formatted string.

1 using System; 2 using System. globalization; 3 4 public class Example 5 {6 public static void Main () 7 {8 Console. writeLine ("'d 'standard format string:"); 9 foreach (var customString in DateTimeFormatInfo. currentInfo. getAllDateTimePatterns ('D') 10 // output the custom formatting string corresponding to the "d" standard formatting character 11 Console. writeLine ("{0}", customString); 12} 13}

 

Related Article

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.