MinguoDate from() method in Java with Example

The MinguoDate class in Java represents a date in the Minguo calendar system used in Taiwan. The from() method is a static factory method that creates a MinguoDate object from a given java.time.LocalDate object.


public static MinguoDate from(java.time.LocalDate isoDate)

Parameters: - isoDate: the ISO local date to convert, not null

Returns: - the Minguo date, not null


import java.time.LocalDate;
import java.time.chrono.MinguoDate;

public class MinguoDateExample {
    public static void main(String[] args) {
        // Creating a LocalDate object
        LocalDate isoDate = LocalDate.of(2021, 10, 10);

        // Converting LocalDate to MinguoDate using from() method
        MinguoDate minguoDate = MinguoDate.from(isoDate);

        // Printing the MinguoDate object
        System.out.println("Minguo Date: " + minguoDate); // Output: Minguo Date: Minguo ROC 110/10/10

In the above example, we first create a LocalDate object representing the date 10th October 2021. We then use the from() method to convert this LocalDate object to a MinguoDate object. Finally, we print the MinguoDate object using the toString() method. The output shows that the Minguo date is "110/10/10" which corresponds to the year 2021 in the Minguo calendar system.

About the author

William Pham is the Admin and primary author of Howto-Code.com. With over 10 years of experience in programming. William Pham is fluent in several programming languages, including Python, PHP, JavaScript, Java, C++.