Last active
February 6, 2023 07:13
-
-
Save erics/8eada72001a03853cff741bdbe3815d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Transfer AD date to minguo date. | |
* 西元年 yyyyMMdd 轉 民國年 yyyMMdd | |
* | |
* @param dateString the String dateString | |
* @return the string | |
*/ | |
public static String transferADDateToMinguoDate(String dateString) { | |
LocalDate localDate = LocalDate.parse(dateString, DateTimeFormatter.ofPattern("yyyyMMdd")); | |
return MinguoDate.from(localDate).format(DateTimeFormatter.ofPattern("yyyMMdd")); | |
} | |
/** | |
* Transfer minguo date to AD date. | |
* 民國年 yyyMMdd 轉 西元年 yyyyMMdd | |
* | |
* @param dateString the String dateString | |
* @return the string | |
*/ | |
public static String transferMinguoDateToADDate(String dateString) { | |
Chronology chrono = MinguoChronology.INSTANCE; | |
DateTimeFormatter df = new DateTimeFormatterBuilder().parseLenient() | |
.appendPattern("yyyMMdd") | |
.toFormatter() | |
.withChronology(chrono) | |
.withDecimalStyle(DecimalStyle.of(Locale.getDefault())); | |
ChronoLocalDate chDate = chrono.date(df.parse(dateString)); | |
return LocalDate.from(chDate).format(DateTimeFormatter.ofPattern("yyyyMMdd")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment