File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TimeZone Conversion

 
Amit Ghilidyal
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Tom P
Ranch Hand
Posts: 88
  • 0
  • Mark post as helpful
  • send pies
  • 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));
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic