• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

TimeZone Conversion

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI
i would appreciate if any one could help me.
I need to convert date generated from a any given timezone
to any other timezone.
thanx
amit
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use the TimeZone and Calendar objects to do all the work for you. You just have to know the time zone id for the time zones you want to convert.
Let's assume that you want to convert from eastern standard time to pacific standard time:
TimeZone tzPST = TimeZone.getTimeZone("PST");
TimeZone tzEST = TimeZone.getTimeZone("EST");
Calendar calPST = new GregorianCalendar(tzPST);
Calendar calEST = new GregorianCalendar(tzEST);
// now load calEST with the time you want to convert
calPST.setTime(calEST.getTime());
//calPST now has the time in pacific standard time
System.out.println(calPST.get(Calendar.HOUR_OF_DAY) + ":" + calPST.get(Calendar.MINUTE));
 
Hey! Wanna see my flashlight? It looks like this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic