Java将⽇期转化为⼤写格式(阿拉伯⼤写数字)效果:
⽇期转化为⼤写格式
代码部分:
public static void main(String[] args) {
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
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-dd");
Date dateTime = null;
try {
dateTime = simpleDateFormat.parse(dateString);
} catch (ParseException e) {
e.printStackTrace();
}
Calendar ca = Instance();
java时间日期格式转换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) + "⽉" + dayToUppder(day) + "⽇";
}
// 将数字转化为⼤写(字体格式可⾃⼰定义)
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] + "")); }
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论