1.西历:
public static String objToDate(Object object) {
String date = objToStr(object);
if (date.length() != 8) {
return date;
} else {
String year = date.substring(0, 4);
String month = date.substring(4, 6);
String day = date.substring(6);
if (!GenericValidator.isDate(date, Constants.FORMAT_DATE, false)) {
return date;
}
StringBuilder sb = new StringBuilder();
sb.append(year);
sb.append(Constants.FORMAT_YEAR);
sb.append(month);
sb.append(Constants.FORMAT_MONTH);
sb.append(day);
sb.append(Constants.FORMAT_DAY);
return sb.toString();
}
2.和历
/**
* ObjectをDate(和暦)に変換する
*
* @param object
* Object
* @return String
*/
public static String objToDateWareki(Object object) {
String date = objToStr(object);
if (date.length() != 8) {
return date;
} else {
int year = Integer.parseInt(date.substring(0, 4));
int month = Integer.parseInt(date.substring(4, 6));
int day = Integer.parseInt(date.substring(6));
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("Gyy年M月d日");
JapaneseDate japaneseDate = JapaneseDate.of(year, month, day);
StringBuilder sb = new StringBuilder();
sb.append(japaneseDate.format(formatter));
return sb.toString();
}
}