Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get the abbreviated timezone using java api ?  RSS feed

mahesh lala
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All ,

I want to get the abbreviated timezone like pst , cst , mdt etc .

Here the things I did .>>

I want to get the abbreviated timezone of the datbase - like cst , PDT, EST etc depending on the db location .

I am using at db > select dbtimezone from dual this gives me timeoffset like -06:00 ie GMT-06:00 . In java I had to take this value and display in the abbreviated form .

for reference

Pls help .

here comes the code I used.( Using hashtable i can get but its not recommended )

* To read data from a table that is present in spread sheet
* Author Mahesh Kumar Lala
* Date 08- 25- 2006.
* Version 1.0
import java.sql.*;
import java.util.Hashtable;
import java.util.Enumeration;
import java.util.TimeZone;

public class GetZone{


public static void main(String[] args){

Connection connection = null;
String UTCTimeZone = null;
Hashtable htbl = new Hashtable();
htbl.put("+00:00", "GMT");
htbl.put("+01:00", "CET");
htbl.put("+02:00", "EET");
htbl.put("-04:00", "EDT");
htbl.put("-05:00", "EST");
htbl.put("-06:00", "CST");
htbl.put("-07:00", "MST");
htbl.put("-08:00", "PST");
htbl.put("+08:00", "WST");
htbl.put("+09:00", "I");
htbl.put("-09:00", "AKST");
htbl.put("+09:30", "ACST");
htbl.put("+10:00", "AEST");
htbl.put("+10:30", "ACDT");
htbl.put("+11:00", "AEDT");

GetZone obj = new GetZone();
System.out.println("==>Driver loaded and registered");
Connection con = DriverManager.getConnection( "xxxxx","user","pwd" )
System.out.println("==>Connection obj is created");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(query);
System.out.println("==>ResultSet obj is created");
ResultSetMetaData rsmd = rs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
System.out.println("==>Reading the column names ");
for (int i = 1; i <= numberOfColumns; i++) {
if (i > 1) System.out.print(" ");
String columnName = rsmd.getColumnName(i);
System.out.println(" ");

while ( {
for (int i = 1; i <= numberOfColumns; i++) {
if (i > 1) System.out.print(" ");
String columnValue = rs.getString(1);
System.out.print("THE ZONE IS FROM DB:- " + columnValue);
String ID = "GMT"+columnValue ;
TimeZone tz = TimeZone.getTimeZone(ID);
System.out.println( "THE TIMEZONE IS " + tz);
System.out.println("getID"+ tz.getID());
System.out.println("DisplayName" + tz.getDisplayName());
System.out.println("DisplayName" + tz.SHORT);


} catch(Exception ex) {
System.err.print("Exception: ");

After getting the dbtimezone , using hashtable and searching into it for key i can get the value like cst est etc but I don't want to use hashtable I want to use java api .

Paul Clapham
Posts: 22185
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Those abbreviations have been sort of deprecated since Java 1.3. If you look in that list to which you posted the link, it doesn't take long to find abbreviations that are ambiguous.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!