• 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

Time Zone Conversion of a String

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could do following:



I am afraid there is no such time zone as "UK".
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28193
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

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.
 
Won't you please? Please won't you be my neighbor? - Fred Rogers. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic