Convert a date to a Chinese character class

Source: Internet
Author: User

I am working on a task. I want to remove the date of birth from my ID card with 15 or 18 digits in the form of 19800825, and then convert the date from year to month to Chinese: O, 8, and 25. below isSource code:

/**/ ///   <Summary>
/// Summary Description for numtochinese
///   </Summary>
///   <Summary>  

/// The date is converted to the Chinese format. The date is removed from the ID card and is not verified for data validity.
/// The procedure for getting the birth date from the ID card will not be written.
/// Joeliang

/// 2007.7.5

///   </Summary>  
Using System;
Using System. Collections. Generic;
Using System. text;

  Public   Class Numtochinese
{
Private   Const   String Chinese =   " ○ September " ;

Public   Static   String Convertyear ( String Year)
{
Stringbuilder result =   New Stringbuilder ();
For ( Int I =   0 ; I < Year. length; I ++ )
{
Result. append (Chinese [Int. Parse (year [I]. tostring ()]);
}
Return Result. tostring ();
}

// The month from the ID card, for example, 12.
Public   Static   String Convertmonth ( String Month)
{
Stringbuilder result =   New Stringbuilder ();

If (Month [ 0 ]. Tostring () =   " 0 " ) // For months from 1 to 9
{
Result. append (Chinese [Int. Parse (month [1]. Tostring ()]);
}
Else
If (Month =   " 10 " ) // If it is July
{
Result. append ("10");
}
Else // For months 11,12
{
Result. append ("10");
Result. append (Chinese [Int. Parse (month [1]. Tostring ()]);
}

Return Result. tostring ();
}

// The date obtained from the ID card, for example
Public   Static   String Convertday ( String Day)
{
Stringbuilder result =   New Stringbuilder ();

If (Day [ 0 ]. Tostring () =   " 0 " ) // If it is a single digit
{
Result. append (Chinese [Int. Parse (day [1]. Tostring ()]);
}
Else
If (Day [ 1 ]. Tostring () =   " 0 " ) // For 10, 20, 30
{
If (Day [ 0 ]. Tostring () =   " 1 " ) // If it is 10
{
}
Else // If it is 20, 30
{
Result. append (Chinese [Int. Parse (day [0]. Tostring ()]);
}
Result. append ( " 10 " );
}
Else // If it is 11,25, 31
{
If (Day [ 0 ]. Tostring () =   " 1 " ) // If it is 11-19
{
}
Else // If it is 21-29,31
{
Result. append (Chinese [Int. Parse (day [0]. Tostring ()]);
}
Result. append ( " 10 " );
Result. append (Chinese [ Int . Parse (day [ 1 ]. Tostring ()]);
}


Return Result. tostring ();
}


}

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.