码迷,mamicode.com
首页 > 其他好文 > 详细

从Date类型转为中文字符串

时间:2016-05-20 19:00:58      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

      //主方法
	public static String DateToCh(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		int year = cal.get(Calendar.YEAR);
		int month = cal.get(Calendar.MONTH) + 1;
		int day = cal.get(Calendar.DAY_OF_MONTH);
		return getYear(year) + getTenString(month) + "月" + getTenString(day) + "日";
	}

	public static String getYear(int year) {
		String result = "";
		for (int i = 0; i < 4; i++) {
			Integer s = Integer.parseInt((year + "").substring(i, i + 1));
			switch (s) {
			case 0:
				result += "〇";
				break;
			case 1:
				result += "一";
				break;
			case 2:
				result += "二";
				break;
			case 3:
				result += "三";
				break;
			case 4:
				result += "四";
				break;
			case 5:
				result += "五";
				break;
			case 6:
				result += "六";
				break;
			case 7:
				result += "七";
				break;
			case 8:
				result += "八";
				break;
			case 9:
				result += "九";
				break;
			default:
				break;
			}
		}
		return result;
	}
	//获取月 日
	public static String getTenString(int ten) {
		String ALL_CN_NUMBER = "一二三四五六七八九";
		if (ten==0){
			return "";
		}else if(ten < 10) {
			return String.valueOf(ALL_CN_NUMBER.charAt(ten - 1));
		} else if (ten == 10) {
			return "十";
		}else {
			String x = getTenString(Integer.parseInt((ten + "").substring(0, 1)));
			String y = getTenString(Integer.parseInt((ten + "").substring(1, 2)));
			return x + "十" + y;
		}
	}

  

从Date类型转为中文字符串

标签:

原文地址:http://www.cnblogs.com/jinjixia/p/5512949.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!