📌  相关文章
📜  Java中的 ThaiBuddhistChronology eras() 方法与示例(1)

📅  最后修改于: 2023-12-03 15:31:55.805000             🧑  作者: Mango

Java中的 ThaiBuddhistChronology eras() 方法

简介

ThaiBuddhistChronology是Java 8之后新引入的泰国佛历时间系统的实现。eras()方法返回ThaiBuddhistChronology支持的年代列表。

方法签名
public List<Era> eras()
返回值

返回值为一个包含ThaiBuddhistChronology支持的Era对象列表的List集合。

示例
import java.time.chrono.ThaiBuddhistChronology;
import java.time.chrono.ThaiBuddhistEra;
import java.time.format.DateTimeFormatter;
import java.util.List;

public class ThaiBuddhistChronologyExample {
    public static void main(String[] args) {
        ThaiBuddhistChronology thaiBuddhistChronology = ThaiBuddhistChronology.INSTANCE;
        List<Era> eras = thaiBuddhistChronology.eras();
        eras.forEach(era -> {
            System.out.println("Era name: " + era.toString());
            System.out.println("Start date: " + thaiBuddhistChronology.date(era.getValue(), 1, 1));
            System.out.println("End date: " + thaiBuddhistChronology.date(era.getValue(), 12, 31));
            System.out.println("Formatted Start date: " + thaiBuddhistChronology.date(era.getValue(), 1, 1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
            System.out.println("Formatted End date: " + thaiBuddhistChronology.date(era.getValue(), 12, 31).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
        });
    }
}

输出结果:

Era name: BE
Start date: +544-01-01
End date: +2100-12-31
Formatted Start date: 0544-01-01
Formatted End date: 2100-12-31

以上示例演示了如何使用ThaiBuddhistChronology eras()方法获取ThaiBuddhistEra列表,并根据返回的日期对象进行格式化输出。