ChronoZonedDateTime

ChronoZonedDateTime is useful when dealing with non-ISO calendar systems (e.g., Japanese, ThaiBuddhist, Hijrah). It holds the complete date (calendar system), time, and time-zone in a way that’s suitable for internationalization.

Common Used Methods

Simple Program

import java.time.chrono.*;
import java.time.*;

public class SimpleChronoZonedDateTimeExample {
    public static void main(String[] args) {
        ChronoZonedDateTime<?> czdt = JapaneseChronology.INSTANCE
                .zonedDateTime(ZonedDateTime.now());

        System.out.println("Chronology: " + czdt.getChronology());
        System.out.println("Date-Time: " + czdt);
        System.out.println("Zone: " + czdt.getZone());
    }
}

Problem Statement:

LotusJavaPrince and Mahesh are developing a historical archive management system that stores date-time information from various cultural and religious calendars (e.g., Japanese, Hijrah, ThaiBuddhist) across different time zones.

  • Support non-Gregorian calendars.
  • Track time zones accurately.
  • Provide conversions between local time and global instant.
import java.time.*;
import java.time.chrono.*;
import java.util.*;

public class HistoricalArchiveManager {
    public static void main(String[] args) {
        Map<String, Chronology> chronologies = Map.of(
                "Asia/Tokyo", JapaneseChronology.INSTANCE,
                "Asia/Dubai", HijrahChronology.INSTANCE,
                "Asia/Bangkok", ThaiBuddhistChronology.INSTANCE
        );

        for (Map.Entry<String, Chronology> entry : chronologies.entrySet()) {
            String zone = entry.getKey();
            Chronology chrono = entry.getValue();

            ZonedDateTime zonedDateTime = ZonedDateTime.of(2024, 5, 22, 9, 0, 0, 0, ZoneId.of(zone));
            ChronoZonedDateTime<?> czdt = chrono.zonedDateTime(zonedDateTime);

            System.out.println("\n--- Archive Entry ---");
            System.out.println("Zone: " + zone);
            System.out.println("Chronology: " + czdt.getChronology());
            System.out.println("Date-Time: " + czdt);
            System.out.println("Offset: " + czdt.getOffset());
        }
    }
}
/*
--- Archive Entry ---
Zone: Asia/Tokyo
Chronology: Japanese
Date-Time: Japanese Heisei 36-05-22T09:00+09:00[Asia/Tokyo]
Offset: +09:00

--- Archive Entry ---
Zone: Asia/Dubai
Chronology: Hijrah
Date-Time: Hijrah-umalqura AH 1445-11-14T09:00+04:00[Asia/Dubai]
Offset: +04:00

--- Archive Entry ---
Zone: Asia/Bangkok
Chronology: ThaiBuddhist
Date-Time: ThaiBuddhist BE 2567-05-22T09:00+07:00[Asia/Bangkok]
Offset: +07:00
*/

ChronoZonedDateTime is a powerful interface for dealing with culturally diverse and time-zone-sensitive date-time values. It provides seamless handling of calendar systems, offsets, and zones, making it an ideal choice for globally distributed applications

Scroll to Top