zoukankan      html  css  js  c++  java
  • 《《《中文的年份更改为阿拉伯数字年份

    转载地址:http://yuncode.net/code/c_5063bcc64c17f59

    关于中文年份转阿拉伯的比较少,找的一个整理一下

      1 package com.ly.changenum;
      2  
      3 /**
      4 * 把中文数字转换为阿拉伯数字,把阿拉伯数字转换为中文数字
      5 *
      6 * @author zhaigy
      7 * @date 2010-2-20
      8 */
      9 final public class Changenum {
     10              
     11      
     12         public static void main(String[] args) {
     13              
     14             String  a   =cnNumToInt("二零〇一年五月一日");
     15             System.err.println(a);
     16         }
     17      
     18 static public String cnNumToInt(String s) {
     19    
     20  String year  = s.substring(0,s.indexOf("年"));
     21  String  month = s.substring(s.indexOf("年")+1,s.indexOf("月"));
     22  String day  = s.substring(s.indexOf("月")+1,s.indexOf("日"));
     23      
     24     String  year_int =changgedate(year);
     25     String month_int =changgedate(month);
     26     String day_int = changgedate(day);
     27   
     28  return  ""+year_int+month_int+day_int;
     29 }
     30  
     31 public static String changgedate(String strs){
     32             String result="";
     33             boolean  flag =false;
     34             if(strs.startsWith("十")){
     35                 flag=true;
     36             }
     37             int  size  =strs.length();
     38              
     39              
     40              
     41             for(int i =1, j=0;i<=strs.length();i++,j++){
     42                         String str = strs.substring(j,i);
     43                 switch (str) {
     44                 case "〇":
     45                     result+=0;
     46                     break;
     47                 case "零":
     48                     result+=0;
     49                     break;
     50                 case "一":
     51                     result+=1;
     52                     break;
     53                 case "二":
     54                     result+=2;
     55                     break;
     56                 case "三":
     57                     result+=3;
     58                     break;
     59                 case "四":
     60                     result+=4;
     61                     break;
     62                 case "五":
     63                     result+=5;
     64                     break;
     65                 case "六":
     66                     result+=6;
     67                     break;
     68                 case "七":
     69                     result+=7;
     70                     break;
     71                 case "八":
     72                     result+=8;
     73                     break;
     74                 case "九":
     75                     result+=9;
     76                     break;
     77                 case "十":
     78                     if(flag&&size==1){
     79                         result+=10;
     80                         break;
     81                     }
     82                     if(!flag&&size==2){
     83                         result+=0;
     84                         break;
     85                     }
     86                     if(size==3){
     87                         break;
     88                     }
     89                     else{
     90                         result+=1;
     91                         break;
     92                     }
     93              
     94                 }
     95             }
     96             if(!flag&&size==1){
     97                 return  "0"+Integer.parseInt(result);
     98             }
     99             else
    100                 return Integer.parseInt(result)+"";
    101     }
    102  
    103   
    104 }

    运行结果

  • 相关阅读:
    访问控制
    静态方法
    类的特殊属性
    Ubuntu Linux 安装配置 MySQL
    Ubuntu16.04 18.04 安装rabbitmq 配置、使用详细教程
    E: The package lists or status file could not be parsed or opened.
    Linux 安装jsoncpp
    gpgkeys: protocol `https’ not supported
    pch文件中调试模式的使用
    ios UITableview 刷新某一个cell 或 section
  • 原文地址:https://www.cnblogs.com/lidar/p/14070664.html
Copyright © 2011-2022 走看看