O'Reilly logo

Java 11 Cookbook by Mohamed Sanaulla, Nick Samoylov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required