java util timezone class

java.util.TimeZone

The Java TimeZone class represents a time zone offset and also figures out daylight savings.

java TimeZone class declaration:

public abstract class TimeZone extends Object  implements Serializable, Cloneable

Java TimeZone class methods

MethodDescription
static String[] getAvailableIDs()Get all the available IDs supported.
static TimeZone getDefault()Get the default TimeZone for this host.
String getDisplayName()Return a name of this time zone suitable for presentation to the user in the default locale.
String getID()Get the ID of this time zone
int getOffset(long date)Return the offset of this time zone from UTC at the specified date.
void setID(String ID)Set the time zone ID

Java timezone getavailableids example

package com.w3spoint;
 
import java.util.TimeZone;
 
public class TimeZoneTest {
	public static void main(String args[]){
	   String[] id = TimeZone.getAvailableIDs();        
	   System.out.println("Available Ids are: "); 
	   for (int i=0; i<id.length; i++){  
		   System.out.println(id[i]); 
	   }
	}
}

Output:

Available Ids are: 
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
Africa/Casablanca
Africa/Ceuta
Africa/Conakry
Africa/Dakar
Africa/Dar_es_Salaam
Africa/Djibouti
Africa/Douala
Africa/El_Aaiun
Africa/Freetown
Africa/Gaborone
Africa/Harare
Africa/Johannesburg
Africa/Juba
Africa/Kampala
Africa/Khartoum
Africa/Kigali
.......

Java timezone getoffset example

package com.w3spoint;
 
import java.util.Calendar;
import java.util.TimeZone;
 
public class TimeZoneTest {
	public static void main(String args[]){
	   TimeZone zone = TimeZone.getTimeZone("Asia/Kolkata");   
	   System.out.println("The Offset value of TimeZone: " +   
	   zone.getOffset(Calendar.ZONE_OFFSET));  
	}
}

Output:

The Offset value of TimeZone: 19800000

Java timezone getid example

package com.w3spoint;
 
import java.util.TimeZone;
 
public class TimeZoneTest {
	public static void main(String args[]){
		TimeZone timezone = TimeZone.getTimeZone("Asia/Kolkata");       
		System.out.println("TimeZone ID: " + timezone.getID());  
	}
}

Output:

TimeZone ID: Asia/Kolkata

Java timezone getdisplayname example

package com.w3spoint;
 
import java.util.TimeZone;
 
public class TimeZoneTest {
	public static void main(String args[]){
		TimeZone zone = TimeZone.getDefault();  
		String name = zone.getDisplayName();         
		System.out.println("Default time zone: "+ name);  
	}
}

Output:

Default time zone: India Standard Time
Content Protection by DMCA.com
Please Share