Western calendar and calendar Functions

Source: Internet
Author: User

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

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.