ZoneId getAvailableZoneIds() method in Java with Examples
The getAvailableZoneIds() method of the ZoneId class used to get the set of available zone IDs.This set includes all available region-based IDs.The ID can be passed to of(String) to create a ZoneId.The set of zone IDs can increase over time, although in a typical application the set of IDs is fixed.
Syntax:
public static Set getAvailableZoneIds()
Parameters: This method does not accepts any parameter.
Return value: This method returns Set which are a modifiable copy of the set of zone IDs.
Below programs illustrate the getAvailableZoneIds() method:
Program 1:
// Java program to demonstrate // ZoneId.getAvailableZoneIds() method import java.time.*; import java.util.Set; public class GFG { public static void main(String[] args) { // get available zones using zoneIds() Set<String> zoneIds = ZoneId.getAvailableZoneIds(); // print first record System.out.println("First ZoneId in list:" + zoneIds.iterator().next()); } } |
First ZoneId in list:Asia/Aden
Program 2:
// Java program to demonstrate // ZoneId.getAvailableZoneIds() method import java.time.*; import java.util.*; public class GFG { public static void main(String[] args) { // get available zones using zoneIds() Set<String> allZones = ZoneId.getAvailableZoneIds(); // create ArrayList from Set List<String> zoneList = new ArrayList<String>(allZones); Collections.sort(zoneList); // printing first 5 zoneid with offset LocalDateTime dt = LocalDateTime.now(); for (int i = 0; i < 5; i++) { // get zoneid then ZonedDateTime and offset // from that ZoneId String s = zoneList.get(i); ZoneId zoneid = ZoneId.of(s); ZonedDateTime zoneddate = dt.atZone(zoneid); ZoneOffset offset = zoneddate.getOffset(); System.out.println("ZoneId = " + zoneid + " offset = " + offset); } } } |
ZoneId = Africa/Abidjan offset = Z ZoneId = Africa/Accra offset = Z ZoneId = Africa/Addis_Ababa offset = +03:00 ZoneId = Africa/Algiers offset = +01:00 ZoneId = Africa/Asmara offset = +03:00
References:
https://docs.oracle.com/javase/10/docs/api/java/time/ZoneId.html#getAvailableZoneIds(java.lang.Object)
Recommended Posts:
- ZoneOffset getAvailableZoneIds() method in Java with Examples
- ZoneId from() method in Java with Examples
- ZoneId hashCode() method in Java with Examples
- ZoneId ofOffset() method in Java with Examples
- ZoneId getDisplayName() method in Java with Examples
- ZoneId toString() method in Java with Examples
- ZoneId systemDefault() method in Java with Examples
- ZoneId normalized() method in Java with Examples
- ZoneId getId() method in Java with Examples
- ZoneId equals() method in Java with Examples
- ZoneId getRules() method in Java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
- Java lang.Long.byteValue() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai



