Java converts the input date to a Chinese Date

Source: Internet
Author: User
ArticleDirectory
    • Java converts the input date to a Chinese date (for example, October 5 -->)
Java converts the input date to a Chinese date (for example, October 5 -->)

 

Package COM. business. practitioner; import Java. text. simpledateformat; import Java. util. date;/*** creation date: October 5 03:41:58 * function: Convert the input date to a Chinese date (for example, -->) Program Assume that the input format is yyyy-mm-dd, and the year, month, and day are numbers, if no illegal * input verification * is added, you can enter 2007-01-05*2007-1-05*2007-10-05 */public class dateconvertor {/*** @ Param ARGs */public static void main (string [] ARGs) {// todo auto-generated method stub string issuedate = "2001-12-25"; system. out. println (getyearstr (formatstr (issuedate);}/*** create Date: 04:29:37 * description: convert a date to a specified format string * @ Param date * @ return */publ IC static string getdatestr (date) {simpledateformat SDF = new simpledateformat ("yyyy-mm-dd"); string datestr = SDF. format (date); Return datestr;}/*** create Date: 03:40:44 * description: retrieve the year string * @ Param STR date string * @ return */public static string getyearstr (string Str) {string yearstr = ""; yearstr = Str. substring (); Return yearstr;}/*** create Date: 03:40:47 * Description: gets the month string * @ Param STR date string * @ return */public static string getmonthstr (string Str) {string m; int startindex = Str. indexof ("year"); int endindex = Str. indexof ("month"); monthstr = Str. substring (startindex + 1, endindex); Return monthstr;}/*** create Date: 03:32:31 * description: format the Arabic numerals in the source string as Chinese characters * @ Param sign * @ return */public static char formatdigit (char sign) {If (Sign = '0 ') s IGN = '0'; If (Sign = '1') Sign = '1'; If (Sign = '2') Sign = '2 '; if (Sign = '3') Sign = '3'; If (Sign = '4') Sign = '4'; If (Sign = '5 ') sign = '5'; If (Sign = '6') Sign = '6'; If (Sign = '7') Sign = '7 '; if (Sign = '8') Sign = '8'; If (Sign = '9') Sign = '9'; return sign ;} /*** create Date: 03:31:51 * description: obtain the length of the month string * @ Param STR source string to be converted * @ Param pos1 location of the First '-' * @ Param pos2 location of the second '-' Location * @ return */public static int getmidlen (string STR, int pos1, int pos2) {return Str. substring (pos1 + 1, pos2 ). length ();}/*** create Date: 03:32:17 * description: obtain the length of the date string * @ Param STR source string to be converted * @ Param pos2 location of the second '-' * @ return */public static int getlastlen (string STR, int pos2) {return Str. substring (pos2 + 1 ). length ();}/*** create Date: 03:40:50 * Description: retrieves the date string * @ Param Str String * @ return */public static string getdaystr (string Str) {string daystr = ""; int startindex = Str. indexof ("month"); int endindex = Str. indexof ("day"); daystr = Str. substring (startindex + 1, endindex); Return daystr;}/*** create Date: 03:32:46 * description: format the character * @ return */public static string formatstr (string Str) in the * @ Param STR source string {stringbuffer sb = new stringbuffer (); int pos1 = Str. indexo F ("-"); int pos2 = Str. lastindexof ("-"); For (INT I = 0; I <4; I ++) {sb. append (formatdigit (Str. charat (I);} sb. append ('Year'); If (getmidlen (STR, pos1, pos2) = 1) {sb. append (formatdigit (Str. charat (5) + "month"); If (Str. charat (7 )! = '0') {If (getlastlen (STR, pos2) = 1) {sb. append (formatdigit (Str. charat (7) + "day");} If (getlastlen (STR, pos2) = 2) {If (Str. charat (7 )! = '1' & Str. charat (8 )! = '0') {sb. append (formatdigit (Str. charat (7) + "10" + formatdigit (Str. charat (8) + "day");} else if (Str. charat (7 )! = '1' & Str. charat (8) = '0') {sb. append (formatdigit (Str. charat (7) + "10");} else if (Str. charat (7) = '1' & Str. charat (8 )! = '0') {sb. append ("Ten" + formatdigit (Str. charat (8) + "day");} else {sb. append ("10") ;}}} else {sb. append (formatdigit (Str. charat (8) + "day") ;}} if (getmidlen (STR, pos1, pos2) = 2) {If (Str. charat (5 )! = '0' & Str. charat (6 )! = '0') {sb. append ("Ten" + formatdigit (Str. charat (6) + "month"); If (getlastlen (STR, pos2) = 1) {sb. append (formatdigit (Str. charat (8) + "day");} If (getlastlen (STR, pos2) = 2) {If (Str. charat (8 )! = '0') {If (Str. charat (8 )! = '1' & Str. charat (9 )! = '0') {sb. append (formatdigit (Str. charat (8) + "10" + formatdigit (Str. charat (9) + "day");} else if (Str. charat (8 )! = '1' & Str. charat (9) = '0') {sb. append (formatdigit (Str. charat (8) + "10");} else if (Str. charat (8) = '1' & Str. charat (9 )! = '0') {sb. append ("Ten" + formatdigit (Str. charat (9) + "day");} else {sb. append ("10") ;}} else {sb. append (formatdigit (Str. charat (9) + "day") ;}} else if (Str. charat (5 )! = '0' & Str. charat (6) = '0') {sb. append ("October"); If (getlastlen (STR, pos2) = 1) {sb. append (formatdigit (Str. charat (8) + "day");} If (getlastlen (STR, pos2) = 2) {If (Str. charat (8 )! = '0') {If (Str. charat (8 )! = '1' & Str. charat (9 )! = '0') {sb. append (formatdigit (Str. charat (8) + "10" + formatdigit (Str. charat (9) + "day");} else if (Str. charat (8 )! = '1' & Str. charat (9) = '0') {sb. append (formatdigit (Str. charat (8) + "10");} else if (Str. charat (8) = '1' & Str. charat (9 )! = '0') {sb. append ("Ten" + formatdigit (Str. charat (9) + "day");} else {sb. append ("10") ;}} else {sb. append (formatdigit (Str. charat (9) + "day") ;}} else {sb. append (formatdigit (Str. charat (6) + "month"); If (getlastlen (STR, pos2) = 1) {sb. append (formatdigit (Str. charat (8) + "day");} If (getlastlen (STR, pos2) = 2) {If (Str. charat (8 )! = '0') {If (Str. charat (8 )! = '1' & Str. charat (9 )! = '0') {sb. append (formatdigit (Str. charat (8) + "10" + formatdigit (Str. charat (9) + "day");} else if (Str. charat (8 )! = '1' & Str. charat (9) = '0') {sb. append (formatdigit (Str. charat (8) + "10");} else if (Str. charat (8) = '1' & Str. charat (9 )! = '0') {sb. append ("Ten" + formatdigit (Str. charat (9) + "day");} else {sb. append ("10") ;}} else {sb. append (formatdigit (Str. charat (9) + "day") ;}}} return sb. 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.