Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Timezone conversion

 
Xiaotian He
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Slight change in the code:
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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"
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic