Tuesday, 18 December 2018

How to use getAvailableIDs() and getAvailableIDs(int rawOffset) methods of java.util.TimeZone class


Click here to watch on Youtube: 
https://www.youtube.com/watch?v=ElnEYtVywXg&list=UUhwKlOVR041tngjerWxVccw

TimeZoneDemo1.java

import java.util.TimeZone;

public class TimeZoneDemo1
{
    public static void main(String[] args)
    {
        /*
         * Returns:an array of IDs.
         */

        String[] idArray = TimeZone.getAvailableIDs();
        for (String id : idArray)
        {
            System.out.println(id);
        }
    }
}

Output

Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Asmera
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau
Africa/Blantyre
Africa/Brazzaville
Africa/Bujumbura
Africa/Cairo

---
---
---

IET
IST
JST
MIT
NET
NST
PLT
PNT
PRT
PST
SST
VST

TimeZoneDemo2.java

import java.util.TimeZone;

public class TimeZoneDemo2
{
    public static void main(String[] args)
    {
        /*
         * Parameters:
         *
         * rawOffset - the given time zone GMT offset in milliseconds.
         *
         * Returns:an array of IDs, where the time zone for that ID
         * has the specified GMT offset. For example,
         * "America/Phoenix" and "America/Denver" both have GMT-07:00,
         * but differ in daylight saving behavior.
         */

        String[] availableIDArray = TimeZone.getAvailableIDs(3600000);

        System.out.println("Available Ids for offset are: ");
        for (String availableID : availableIDArray)
        {
            System.out.println(availableID);
        }
    }
}

Output

Available Ids for offset are:
Africa/Algiers
Africa/Bangui
Africa/Brazzaville
Africa/Ceuta
Africa/Douala
Africa/Kinshasa
Africa/Lagos
Africa/Libreville

---
---

Europe/Stockholm
Europe/Tirane
Europe/Vaduz
Europe/Vatican
Europe/Vienna
Europe/Warsaw
Europe/Zagreb
Europe/Zurich
MET
Poland

Click the below link to download the code:
https://sites.google.com/site/ramj2eev2/java_basics/TimeZoneDemo_getAvailableIDs.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava_2018/TimeZoneDemo_getAvailableIDs

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/5bada39e8532ab4b75aaa28b80cdcee21bf19ab7/BasicJava_2018/TimeZoneDemo_getAvailableIDs/?at=master

See also:
  • All JavaEE Videos Playlist
  • All JavaEE Videos
  • All JAVA EE Links
  • Spring Tutorial
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • Cooking Tutorial
  • No comments:

    Post a Comment