During Japanese development, you may often encounter conversion of date formats. The biggest headache is that the system time is converted to Japan and calendar.
Most of the time, everyone writes their own functions to calculate the Emperor's time in various periods in Japan for conversion. In fact,. Net already has the built-in Japanese calendar computing.Algorithm.
UseCalendar andIn the calendar class, we can easily convert the calendars and calendars, without having to write a lotCodeAnd calendar calculation.
Example 1 of the West calendar and calendar functions: Format (equal to year, month, and day)
1 Stringbuilder strmsg = New Stringbuilder ();
2
3 Strmsg. append (system. environment. newline + String . Format ( " {0:00:00} " , 0100 ));
4 Strmsg. append (system. environment. newline + String . Format ( " {0: #0: 00} " , 0100 ));
5
6 System. Globalization. cultureinfo Ci = New System. Globalization. cultureinfo ( " Ja-JP " );
7 System. Globalization. Calendar Cal = New System. Globalization. japanesecalendar ();
8 CI. datetimeformat. Calendar = Cal;
9 MessageBox. Show (datetime. parse ( " 1990/09/06 " ). Tostring ( " GGY-m-d " , CI) + Strmsg. tostring ());
There are many date formats in row 9th
1. GGY-m-d
2. GGY-mm-d
3. GGY-mm-dd
4.mm dd, GGY
The principle is very simple and you don't need to explain it. If you don't understand it, you can test it on your own.
Example 2 of the West calendar and calendar functions: Format (H, month, and day)
1 System. Globalization. cultureinfo Ci = New System. Globalization. cultureinfo ( " Ja-JP " );
2 System. Globalization. Calendar Cal = New System. Globalization. japanesecalendar ();
3 CI. datetimeformat. Calendar = Cal;
4
5 Datetime dt = Datetime. parse ( " 2006/09/26 " );
6 Type T = Typeof (System. Globalization. datetimeformatinfo );
7 System. reflection. propertyinfo pi = T. getproperty ( " Abbreviatedenglisheranames " , System. reflection. bindingflags. nonpublic | System. reflection. bindingflags. instance );
8
9 String [] Engeras = ( String []) PI. getvalue (CI. datetimeformat, Null );
10 Int Era = Cal. geloud (DT );
11 String Strwareki = Engeras [Era - 1 ] + DT. tostring ( " YY/MM/dd " , CI );
12
13 MessageBox. Show (strwareki ); // Output: H18/09/26