ZonedDateTime

In this lesson, we will explore the ZonedDateTime class and its methods.

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.

Press + to interact
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)

...