zoukankan      html  css  js  c++  java
  • 日期转换为中文

     public static void main(String[] args){
            SpringApplication.run(Application.class, args);
    
    //        String dateString = "2020-07-08";
            SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM");
            String beforedate=sdf.format(new Date());
            System.out.println("转换之前:"+beforedate);
            String enddate=dataToUpper(beforedate);
            System.out.println("转换之后:"+enddate);
    
        }
        // 日期转化为大小写
        public static String dataToUpper(String dateString) {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
            Date dateTime = null;
            try {
                dateTime = simpleDateFormat.parse(dateString);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            Calendar ca = Calendar.getInstance();
            ca.setTime(dateTime);
            int year = ca.get(Calendar.YEAR);
            int month = ca.get(Calendar.MONTH) + 1;
    //        int day = ca.get(Calendar.DAY_OF_MONTH);
            return numToUpper(year) + "" + monthToUppder(month) + "";
        }
        public static String numToUpper(int num) {
            //String u[] = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
            String u[] = {"","","","","","","","","",""};
            char[] str = String.valueOf(num).toCharArray();
            String rstr = "";
            for (int i = 0; i < str.length; i++) {
                rstr = rstr + u[Integer.parseInt(str[i] + "")];
            }
            return rstr;
        }
    
        // 月转化为大写
        public static String monthToUppder(int month) {
            if(month < 10) {
                return numToUpper(month);
            } else if(month == 10){
                return "";
            } else {
                return "" + numToUpper(month - 10);
            }
        }
    
        // 日转化为大写
        public static String dayToUppder(int day) {
            if(day < 20) {
                return monthToUppder(day);
            } else {
                char[] str = String.valueOf(day).toCharArray();
                if(str[1] == '0') {
                    return numToUpper(Integer.parseInt(str[0] + "")) + "";
                }else {
                    return numToUpper(Integer.parseInt(str[0] + "")) + "" + numToUpper(Integer.parseInt(str[1] + ""));
                }
            }
        }
  • 相关阅读:
    CodeForces Gym 100500A A. Poetry Challenge DFS
    CDOJ 486 Good Morning 傻逼题
    CDOJ 483 Data Structure Problem DFS
    CDOJ 482 Charitable Exchange bfs
    CDOJ 481 Apparent Magnitude 水题
    Codeforces Gym 100637G G. #TheDress 暴力
    Gym 100637F F. The Pool for Lucky Ones 暴力
    Codeforces Gym 100637B B. Lunch 找规律
    Codeforces Gym 100637A A. Nano alarm-clocks 前缀和
    TC SRM 663 div2 B AABB 逆推
  • 原文地址:https://www.cnblogs.com/zhouziyan/p/13391131.html
Copyright © 2011-2022 走看看