How it works…

First, let's look at how the time zone information is captured. It's captured based on the number of hours and minutes from Greenwich Mean Time (GMT), also known as Coordinated Universal Time (UTC). For example, Indian Standard Time (IST), also known as Asia/Kolkata, is 5:30 hours ahead of GMT. 

Java provides java.time.ZoneId and java.time.ZoneOffset to represent time zone information. java.time.ZoneId captures time zone information based on the time zone name, such as Asia/Kolkata, US/Pacific, and US/Mountain. There are around 599 zone IDs. This has been computed using the following line of code:

jshell> ZoneId.getAvailableZoneIds().stream().count()$16 ==> 599

We will print 10 of the zone IDs:

jshell> ZoneId.getAvailableZoneIds().stream().limit(10).forEach(System.out::println) ...

Get Java 11 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.