File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Reg: Retriveing timezone from timestamp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Reg: Retriveing timezone from timestamp " Watch "Reg: Retriveing timezone from timestamp " New topic

Reg: Retriveing timezone from timestamp

Chethan Sharma
Ranch Hand

Joined: Mar 22, 2006
Posts: 59

I have a requirement to parse the timestamp and get the timezone from it:

timestamp is in the format of 'Thu Mar 11 18:25:14 GMT-08:00 2010'.

From this string, I need to get the timezone (as PST in above example).

I am using the SimpleDateFormat as 'EEE MMM dd HH:mm:ss z yyyy' for parsing but the timezone is showing as IST.

following is the code i have tried :
SimpleDateFormat SDF = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
String testdate = "Thu Mar 11 18:25:14 GMT-08:00 2010";

India Standard Time.

if I rewrite 'testdate' with "Thu Mar 11 18:25:14 PST 2010", output is coming correctly as 'PST'.

Please let me know how to retireve the correct timezone in the above code ?

Also, I have tried taking timezone substring from the testdate as 'GMT-08:00' and pass it to TimeZone class like :
But the output is shown as 'GMT-08:00' but not the 'PST'.

Please help me to achieve the desired output.

I agree. Here's the link:
subject: Reg: Retriveing timezone from timestamp
It's not a secret anymore!