签署投资协议
parent
39aac69ac9
commit
0f24bb9ad6
@ -0,0 +1,98 @@
|
||||
package com.sztzjy.fund_investment.util;
|
||||
import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 日期转成中文大写形式
|
||||
*
|
||||
*/
|
||||
public class DateToUpperChinese {
|
||||
|
||||
private static final String[] NUMBERS = { "零", "壹", "贰", "叁", "肆", "伍",
|
||||
"陆", "柒", "捌", "玖" };
|
||||
|
||||
/** 通过 yyyy-MM-dd 得到中文大写格式 yyyy MM dd 日期 */
|
||||
public static synchronized String toChinese(Date newDate) {
|
||||
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String str = outputFormat.format(newDate);
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(getSplitDateStr(str, 0)).append("年").append(
|
||||
getSplitDateStr(str, 1)).append("月").append(
|
||||
getSplitDateStr(str, 2)).append("日");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/** 分别得到年月日的大写 默认分割符 "-" */
|
||||
public static String getSplitDateStr(String str, int unit) {
|
||||
// unit是单位 0=年 1=月 2日
|
||||
String[] DateStr = str.split("-");
|
||||
if (unit > DateStr.length)
|
||||
unit = 0;
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < DateStr[unit].length(); i++) {
|
||||
|
||||
if ((unit == 1 || unit == 2) && Integer.valueOf(DateStr[unit]) > 9) {
|
||||
sb.append(convertNum(DateStr[unit].substring(0, 1)))
|
||||
.append("拾").append(
|
||||
convertNum(DateStr[unit].substring(1, 2)));
|
||||
break;
|
||||
} else {
|
||||
sb.append(convertNum(DateStr[unit].substring(i, i + 1)));
|
||||
}
|
||||
}
|
||||
if (unit == 1 || unit == 2) {
|
||||
return sb.toString().replaceAll("^壹", "").replace("零", "");
|
||||
}
|
||||
return sb.toString();
|
||||
|
||||
}
|
||||
|
||||
/** 转换数字为大写 */
|
||||
private static String convertNum(String str) {
|
||||
return NUMBERS[Integer.valueOf(str)];
|
||||
}
|
||||
|
||||
/** 判断是否是零或正整数 */
|
||||
public static boolean isNumeric(String str) {
|
||||
Pattern pattern = Pattern.compile("[0-9]*");
|
||||
Matcher isNum = pattern.matcher(str);
|
||||
if (!isNum.matches()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
|
||||
|
||||
System.out.println(toChinese(DateUtil.parse("2008-10-24")));
|
||||
|
||||
// 获取当前日期
|
||||
Date currentDate = new Date();
|
||||
|
||||
// 将日期转换为Calendar对象
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(currentDate);
|
||||
|
||||
// 将月份增加1
|
||||
calendar.add(Calendar.MONTH, 1);
|
||||
|
||||
// 获取加一个月后的日期
|
||||
Date newDate = calendar.getTime();
|
||||
|
||||
// // 将 Date 对象格式化为 "yyyy-MM-dd" 的字符串
|
||||
// SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
// String outputDateString = outputFormat.format(newDate);
|
||||
// System.out.println(outputDateString);
|
||||
|
||||
System.out.println(toChinese(newDate));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue