• 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
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Java Timezone conversion

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tried following code to do timezone conversion and failed to get correct results. Tried "CDT", "CST", "PDT" and "PST", etc. Please help.


public static String ConvertTmz(String timeFormat, String timeStr, String tmz){
String theTimeFormat="MM/dd/yyyy HH:mm:ss";
if (timeFormat!=null) theTimeFormat=timeFormat;
SimpleDateFormat sdf = new SimpleDateFormat(theTimeFormat);

sdf.setTimeZone(TimeZone.getTimeZone(tmz));

GetTimeStr(timeStr);
GregorianCalendar time=new GregorianCalendar(yyyy, mm-1, dd, hh, mi, ss);
return sdf.format(time.getTime());

}
 
Xiaotian He
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Slight change in the code:
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Xiaotian He wrote:Tried following code to do timezone conversion and failed to get correct results. Tried "CDT", "CST", "PDT" and "PST", etc. Please help.


What is, in your opinion, a "correct result" - what output do you expect, and what do you get, and how are these different?
 
Xiaotian He
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fri Mar 22 09:23:19 GMT-06:00 2013.......... After EDT: 03/22/2013 15:23:19
Fri Mar 22 09:24:22 GMT-06:00 2013.......... After CDT: 03/22/2013 15:24:22
Fri Mar 22 09:25:01 GMT-06:00 2013.......... After PDT: 03/22/2013 15:25:01

Something must be wrong with using "EDT", "CDT" or "PDT"
 
Space pants. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic