o7planning

Java MinguoDate Tutorial with Examples

  1. MinguoDate
  2. MinguoDate Examples
  3. MinguoDate Methods

1. MinguoDate

The MinguoDate class represents dates in the Republic of China (ROC) calendar system, also known as the Minguo calendar. This calendar has been in used since as early as 1912, the year of the foundation of the Republic of China. January 1, 1912 in the ISO calendar system is equivalent to January 1, year 1 in the Minguo calendar. The term "Minguo" simply means "republic" (traditional Chinese: 民國; simplified Chinese: 民国).
Minguo follows the Chinese tradition of using the name of the era and year of rule, like the Chinese dynasties that preceded it. However, months and days are numbered according to the Gregorian (ISO) calendar. This calendar system has only 2 eras, BEFORE_ROC (Before Republic of China) and ROC (Republic of China) representing the period before and after 1912. In fact, Chinese feudalism ended on February 12, 1912 when Yaozhi the last emperor of China was forced to abdicate.
The ROC calendar has been in wide use in the Republic of China since 1912, including in early official documents. The ROC calendar is the official calendar used in Taiwan since 1945, and also adopted by Overseas Chinese and Taiwanese communities. Chorographies and historical research published in mainland China covering the period between 1912 and 1949 also use the ROC calendar.

2. MinguoDate Examples

Convert an ISO date to a Minguo date and vice versa:
MinguoDate_from_ex1.java
LocalDate localDate = LocalDate.of(2000, 2, 15);
// Convert Minguo Date to ISO Date
MinguoDate minguoDate = MinguoDate.from(localDate);

System.out.printf("ISO Date: %s, Minguo Date: %s%n%n", localDate, minguoDate);  

minguoDate = MinguoDate.of(100, 1, 1);
// Convert ISO Date to Minguo Date
localDate = LocalDate.from(minguoDate);
System.out.printf("Minguo Date: %s, ISO Date: %s%n", minguoDate, localDate);
Output:
ISO Date: 2000-02-15, Minguo Date: Minguo ROC 89-02-15

Minguo Date: Minguo ROC 100-01-01, ISO Date: 2011-01-01
Example: View the era information of a MinguoDate object.
MinguoDate_ex2.java
MinguoDate minguoDate = MinguoDate.of(50, 3, 15);
MinguoEra era =    minguoDate.getEra();

System.out.printf("Minguo Date: %s, ISO Date: %s%n", minguoDate, LocalDate.from(minguoDate));
System.out.println(" > Era: " + era.name() +", value: " + era.getValue());


minguoDate = MinguoDate.of(-10, 3, 15);  
 era =    minguoDate.getEra();
System.out.printf("%nMinguo Date: %s, ISO Date: %s%n", minguoDate, LocalDate.from(minguoDate));
System.out.println(" > Era: " + era.name() +", value: " + era.getValue());
Output:
Minguo Date: Minguo ROC 50-03-15, ISO Date: 1961-03-15
 > Era: ROC, value: 1

Minguo Date: Minguo BEFORE_ROC 11-03-15, ISO Date: 1901-03-15
 > Era: BEFORE_ROC, value: 0
  • Java MinguoEra

3. MinguoDate Methods

Factory methods:
public static MinguoDate now()  

public static MinguoDate now(ZoneId zone)  

public static MinguoDate now(Clock clock)  

public static MinguoDate of(int prolepticYear, int month, int dayOfMonth)

public static MinguoDate from(TemporalAccessor temporal)
Other methods:
public MinguoChronology getChronology()   
public MinguoEra getEra()   

public int lengthOfMonth()
public ValueRange range(TemporalField field)
public long getLong(TemporalField field)  
public MinguoDate with(TemporalField field, long newValue)
public MinguoDate with(TemporalAdjuster adjuster)  
public MinguoDate plus(TemporalAmount amount)  
public MinguoDate minus(TemporalAmount amount)  
public MinguoDate plus(long amountToAdd, TemporalUnit unit)  
public MinguoDate minus(long amountToAdd, TemporalUnit unit)
public final ChronoLocalDateTime<MinguoDate> atTime(LocalTime localTime)  
public long toEpochDay()  
public ChronoPeriod until(ChronoLocalDate endDate)  
public long until(Temporal endExclusive, TemporalUnit unit)
Basically, MinguoDate methods are similar to LocalDate methods. You can see the article about the LocalDate class to have more examples: