Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Time Zone Conversion of a String

 
Manu Garg
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use SimpleDateFormat class to apply Date and Time Patterns.
 
Manu Garg
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could do following:



I am afraid there is no such time zone as "UK".
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Pie
Posts: 20750
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic