• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get the abbreviated timezone using java api ?

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 http://www.timeanddate.com/library/abbreviations/timezones/

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.io.*;
import java.sql.*;
import java.util.Hashtable;
import java.util.Enumeration;
import java.util.TimeZone;


public class GetZone{

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");

try{
GetZone obj = new GetZone();
Class.forName("oracle.jdbc.OracleDriver");
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();
String query = " SELECT DBTIMEZONE FROM DUAL";
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.print(columnName);
}
System.out.println(" ");

while (rs.next()) {
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);

}
System.out.println("");
}

st.close();
con.close();
} catch(Exception ex) {
System.err.print("Exception: ");
System.err.println(ex.getMessage());
}
}
}

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 .

thanks
mahesh
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Well don't expect me to do the dishes! This ad has been cleaned for your convenience:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic