1- //<snippet1>
2- // This code example demonstrates the DateTimeFormatInfo
3- // MonthGenitiveNames, AbbreviatedMonthGenitiveNames,
4- // ShortestDayNames, and NativeCalendarName properties, and
5- // the GetShortestDayName() and SetAllDateTimePatterns() methods.
6-
7- using System ;
1+ using System ;
82using System . Globalization ;
93
104class Sample
115{
126 public static void Main ( )
137 {
14- string [ ] myDateTimePatterns = new string [ ] { "MM/dd/yy" , "MM/dd/yyyy" } ;
15-
16- // Get the en-US culture.
17- CultureInfo ci = new CultureInfo ( "en-US" ) ;
18- // Get the DateTimeFormatInfo for the en-US culture.
19- DateTimeFormatInfo dtfi = ci . DateTimeFormat ;
20-
21- // Display the effective culture.
22- Console . WriteLine ( "This code example uses the {0} culture." , ci . Name ) ;
23-
24- // Display the native calendar name.
25- Console . WriteLine ( "\n NativeCalendarName..." ) ;
26- Console . WriteLine ( "\" {0}\" " , dtfi . NativeCalendarName ) ;
27-
28- // Display month genitive names.
29- Console . WriteLine ( "\n MonthGenitiveNames..." ) ;
30- foreach ( string name in dtfi . MonthGenitiveNames )
31- {
32- Console . WriteLine ( "\" {0}\" " , name ) ;
33- }
34-
35- // Display abbreviated month genitive names.
36- Console . WriteLine ( "\n AbbreviatedMonthGenitiveNames..." ) ;
37- foreach ( string name in dtfi . AbbreviatedMonthGenitiveNames )
38- {
39- Console . WriteLine ( "\" {0}\" " , name ) ;
40- }
41-
42- // Display shortest day names.
43- Console . WriteLine ( "\n ShortestDayNames..." ) ;
44- foreach ( string name in dtfi . ShortestDayNames )
45- {
46- Console . WriteLine ( "\" {0}\" " , name ) ;
47- }
48-
49- // Display shortest day name for a particular day of the week.
50- Console . WriteLine ( "\n GetShortestDayName(DayOfWeek.Sunday)..." ) ;
51- Console . WriteLine ( "\" {0}\" " , dtfi . GetShortestDayName ( DayOfWeek . Sunday ) ) ;
52-
53- // Display the initial DateTime format patterns for the 'd' format specifier.
54- Console . WriteLine ( "\n Initial DateTime format patterns for the 'd' format specifier..." ) ;
55- foreach ( string name in dtfi . GetAllDateTimePatterns ( 'd' ) )
56- {
57- Console . WriteLine ( "\" {0}\" " , name ) ;
58- }
59-
60- // Change the initial DateTime format patterns for the 'd' DateTime format specifier.
61- Console . WriteLine ( "\n Change the initial DateTime format patterns for the \n " +
62- "'d' format specifier to my format patterns..." ) ;
63- dtfi . SetAllDateTimePatterns ( myDateTimePatterns , 'd' ) ;
64-
65- // Display the new DateTime format patterns for the 'd' format specifier.
66- Console . WriteLine ( "\n New DateTime format patterns for the 'd' format specifier..." ) ;
67- foreach ( string name in dtfi . GetAllDateTimePatterns ( 'd' ) )
68- {
69- Console . WriteLine ( "\" {0}\" " , name ) ;
70- }
8+ //<snippet1>
9+ string [ ] myDateTimePatterns = [ "MM/dd/yy" , "MM/dd/yyyy" ] ;
10+
11+ // Get the en-US culture.
12+ CultureInfo ci = new ( "en-US" ) ;
13+ // Get the DateTimeFormatInfo for the en-US culture.
14+ DateTimeFormatInfo dtfi = ci . DateTimeFormat ;
15+
16+ // Display the effective culture.
17+ Console . WriteLine ( "This code example uses the {0} culture." , ci . Name ) ;
18+
19+ // Display the native calendar name.
20+ Console . WriteLine ( "\n NativeCalendarName..." ) ;
21+ Console . WriteLine ( $ "\" { dtfi . NativeCalendarName } \" ") ;
22+
23+ // Display month genitive names.
24+ Console . WriteLine ( "\n MonthGenitiveNames..." ) ;
25+ foreach ( string name in dtfi . MonthGenitiveNames )
26+ {
27+ Console . WriteLine ( $ "\" { name } \" ") ;
28+ }
29+
30+ // Display abbreviated month genitive names.
31+ Console . WriteLine ( "\n AbbreviatedMonthGenitiveNames..." ) ;
32+ foreach ( string name in dtfi . AbbreviatedMonthGenitiveNames )
33+ {
34+ Console . WriteLine ( $ "\" { name } \" ") ;
35+ }
36+
37+ // Display shortest day names.
38+ Console . WriteLine ( "\n ShortestDayNames..." ) ;
39+ foreach ( string name in dtfi . ShortestDayNames )
40+ {
41+ Console . WriteLine ( $ "\" { name } \" ") ;
42+ }
43+
44+ // Display shortest day name for a particular day of the week.
45+ Console . WriteLine ( "\n GetShortestDayName(DayOfWeek.Sunday)..." ) ;
46+ Console . WriteLine ( $ "\" { dtfi . GetShortestDayName ( DayOfWeek . Sunday ) } \" ") ;
47+
48+ // Display the initial DateTime format patterns for the 'd' format specifier.
49+ Console . WriteLine ( "\n Initial DateTime format patterns for the 'd' format specifier..." ) ;
50+ foreach ( string name in dtfi . GetAllDateTimePatterns ( 'd' ) )
51+ {
52+ Console . WriteLine ( $ "\" { name } \" ") ;
53+ }
54+
55+ // Change the initial DateTime format patterns for the 'd' DateTime format specifier.
56+ Console . WriteLine ( "\n Change the initial DateTime format patterns for the \n " +
57+ "'d' format specifier to my format patterns..." ) ;
58+ dtfi . SetAllDateTimePatterns ( myDateTimePatterns , 'd' ) ;
59+
60+ // Display the new DateTime format patterns for the 'd' format specifier.
61+ Console . WriteLine ( "\n New DateTime format patterns for the 'd' format specifier..." ) ;
62+ foreach ( string name in dtfi . GetAllDateTimePatterns ( 'd' ) )
63+ {
64+ Console . WriteLine ( $ "\" { name } \" ") ;
65+ }
66+
67+ /*
68+ Output:
69+
70+ This code example uses the en-US culture.
71+
72+ NativeCalendarName...
73+ "Gregorian Calendar"
74+
75+ MonthGenitiveNames...
76+ "January"
77+ "February"
78+ "March"
79+ "April"
80+ "May"
81+ "June"
82+ "July"
83+ "August"
84+ "September"
85+ "October"
86+ "November"
87+ "December"
88+ ""
89+
90+ AbbreviatedMonthGenitiveNames...
91+ "Jan"
92+ "Feb"
93+ "Mar"
94+ "Apr"
95+ "May"
96+ "Jun"
97+ "Jul"
98+ "Aug"
99+ "Sep"
100+ "Oct"
101+ "Nov"
102+ "Dec"
103+ ""
104+
105+ ShortestDayNames...
106+ "S"
107+ "M"
108+ "T"
109+ "W"
110+ "T"
111+ "F"
112+ "S"
113+
114+ GetShortestDayName(DayOfWeek.Sunday)...
115+ "S"
116+
117+ Initial DateTime format patterns for the 'd' format specifier...
118+ "M/d/yyyy"
119+ "MMM d, yyyy"
120+ "M/d/yy"
121+
122+ Change the initial DateTime format patterns for the
123+ 'd' format specifier to my format patterns...
124+
125+ New DateTime format patterns for the 'd' format specifier...
126+ "MM/dd/yy"
127+ "MM/dd/yyyy"
128+
129+ */
130+ //</snippet1>
71131 }
72132}
73- /*
74- This code example produces the following results:
75-
76- This code example uses the en-US culture.
77-
78- NativeCalendarName...
79- "Gregorian Calendar"
80-
81- MonthGenitiveNames...
82- "January"
83- "February"
84- "March"
85- "April"
86- "May"
87- "June"
88- "July"
89- "August"
90- "September"
91- "October"
92- "November"
93- "December"
94- ""
95-
96- AbbreviatedMonthGenitiveNames...
97- "Jan"
98- "Feb"
99- "Mar"
100- "Apr"
101- "May"
102- "Jun"
103- "Jul"
104- "Aug"
105- "Sep"
106- "Oct"
107- "Nov"
108- "Dec"
109- ""
110-
111- ShortestDayNames...
112- "Su"
113- "Mo"
114- "Tu"
115- "We"
116- "Th"
117- "Fr"
118- "Sa"
119-
120- GetShortestDayName(DayOfWeek.Sunday)...
121- "Su"
122-
123- Initial DateTime format patterns for the 'd' format specifier...
124- "M/d/yyyy"
125- "M/d/yy"
126- "MM/dd/yy"
127- "MM/dd/yyyy"
128- "yy/MM/dd"
129- "yyyy-MM-dd"
130- "dd-MMM-yy"
131-
132- Change the initial DateTime format patterns for the
133- 'd' format specifier to my format patterns...
134-
135- New DateTime format patterns for the 'd' format specifier...
136- "MM/dd/yy"
137- "MM/dd/yyyy"
138-
139- */
140- //</snippet1>
0 commit comments