File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
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: 14428
    
  23

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 8 API documentation
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