Search⌘ K
AI Features

ZonedDateTime

Explore how to create and manipulate ZonedDateTime objects using Java 8 Time API. Understand how to work with ZoneId, retrieve date and time components, and modify date or time values with various methods. Gain practical skills to handle time zone-aware date and time in your Java applications.

The ZonedDateTime class represents a date and a time with time zone information. While creating an instance of ZonedDateTime, we need to provide a ZoneId. The ZoneId is an identifier used to represent different zones. Before we proceed towards ZonedDateTime, let’s look at ZoneId briefly.

The below example shows how to get a ZoneId for a given Zone.

Java
import java.time.ZoneId;
import java.util.Set;
class DateTimeDemo {
public static void main(String args[]) {
//Fetching the Zoneid for given Zone.
ZoneId zoneId = ZoneId.of("America/Marigot");
System.out.println("Zone Id " + zoneId);
//Fetching a Set of all Zoneids
Set<String> zoneIdList = ZoneId.getAvailableZoneIds();
for (String zone : zoneIdList) {
System.out.println(zone);
}
}
}

1)

...