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}