• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Reg: Retriveing timezone from timestamp

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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";
SDF.parse(testdate);
System.out.println("SDF.getTimeZone().getDisplayName());
**/

Output:
==========
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 :
/**
System.out.println(TimeZone.getTimeZone("GMT-08:00").getID());
**/
But the output is shown as 'GMT-08:00' but not the 'PST'.

Please help me to achieve the desired output.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic