wood burning stoves 2.0*
The moose likes Java in General and the fly likes Time Zone Conversion of a String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Time Zone Conversion of a String" Watch "Time Zone Conversion of a String" New topic
Author

Time Zone Conversion of a String

Manu Garg
Greenhorn

Joined: Feb 06, 2006
Posts: 6
Hi All,

I am parsing an XML file which provides me Date,Time Zone for UK and US. Date is fine but the time it provides me is in the Formate 17:00:00 UK and corresponding 12:00:00 US for same event. I would like to convert the time in the Formate 12:00 PM for US and 5:00 PM for UK. Can some one help me how I can acheive this.
I have a separate object which contain both this information, I tried setting the TimeZone to UK and US but didn't work any help will be appreciated
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

you can use SimpleDateFormat class to apply Date and Time Patterns.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Manu Garg
Greenhorn

Joined: Feb 06, 2006
Posts: 6
Hi,

Thanks for replying, This is the XML formate which has Date,Time and TimeZone in separate attribute. Which I am populating in the separate String.
<DisplayableDateTime TimeZone="ET" EventStartDate="20080507" EventStartTime="12:00:00"/>
<DisplayableDateTime TimeZone="UKT" EventStartDate="20080507" EventStartTime="17:00:00"/>
i.e
String TimeZone = ET
String StartDate =20080507
StartTime = 12:00:00
etc.....
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

here is an example. that shows how to format time to have a AM/PM text using Java SimpleDateFormat.

hope it helps.
[ June 11, 2008: Message edited by: Muhammad Saifuddin ]
Manu Garg
Greenhorn

Joined: Feb 06, 2006
Posts: 6
Thanks again...This code can work only for the UST since the time for the UK will be different. I think I will have to set the locale before issuing the SimpleDateFormate...
Vilmantas Baranauskas
Ranch Hand

Joined: Dec 20, 2006
Posts: 89
You could do following:



I am afraid there is no such time zone as "UK".


Author of <a href="http://www.newsinjector.com" target="_blank" rel="nofollow">NewsInjector</a>
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
And the idea of a "UST" is even more nonsensical. We've got four time zones in the continental US, plus at least two for Alaska and Hawaii. I'm too lazy to look up other places like Guam to see how they would change the total, or to argue about whether they should be considered. And inconsistencies in the adoption of Daylight Saving Time (evil blight on humanity that it is) make the issue even more complicated. If you want to see a 5-hour difference between the "US" and Britain, then you must mean the East Coast of the US. If you use TimeZone.getTimeZone("America/New_York"), that should work.


"I'm not back." - Bill Harding, Twister
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

Originally posted by Jim Yingst:
If you want to see a 5-hour difference between the "US" and Britain, then you must mean the East Coast of the US.
Yes, that's most likely what "ET" meant in the original XML example.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Time Zone Conversion of a String