aspose file tools*
The moose likes Java in General and the fly likes Java Timezone conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java Timezone conversion" Watch "Java Timezone conversion" New topic
Author

Java Timezone conversion

Xiaotian He
Greenhorn

Joined: Jun 19, 2012
Posts: 15
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

Joined: Jun 19, 2012
Posts: 15
Slight change in the code:
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14108
    
  16

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?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Xiaotian He
Greenhorn

Joined: Jun 19, 2012
Posts: 15
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
 
subject: Java Timezone conversion