Java - Convert dates in one calendar system to another.

Introduction

ISO dates to non-ISO dates conversion is allowed.

The following code shows how to convert ISO date to Thai Buddhist date and vice versa.

Demo

import java.time.LocalDate;
import java.time.chrono.ThaiBuddhistDate;

public class Main {
  public static void main(String[] args) {
    ThaiBuddhistDate thaiBuddhistNow = ThaiBuddhistDate.now();
    LocalDate isoNow = LocalDate.now();
    System.out.println("Thai Buddhist Current Date: " + thaiBuddhistNow);
    System.out.println("ISO Current Date: " + isoNow);
    // Convert Thai Buddhist date to ISO date and vice versa
    ThaiBuddhistDate thaiBuddhistNow2 = ThaiBuddhistDate.from(isoNow);
    LocalDate isoNow2 = LocalDate.from(thaiBuddhistNow);
    System.out.println("Thai Buddhist Current Date from ISO: "
        + thaiBuddhistNow2);//from   w  w w.j av a2  s  .c  o  m
    System.out.println("ISO Current Date from Thai Buddhist: " + isoNow2);
  }
}

Result

Related Topic