aspose file tools*
The moose likes Java in General and the fly likes Unusual date formatting problem 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 "Unusual date formatting problem" Watch "Unusual date formatting problem" New topic
Author

Unusual date formatting problem

achana chan
Ranch Hand

Joined: Jul 29, 2002
Posts: 277
Hi, just when I think I understand how to format dates as strings.
Why is there a big difference between the date-time after formatting the date?
I'm running this on Solaris 6.
[code]
int ONE_HOUR = 1*1000*60*60;
SimpleTimeZone LocalTimeZone = new SimpleTimeZone(8*ONE_HOUR, "GMT+08:00");
TimeZone.setDefault(LocalTimeZone );

out.println("1. The time is: " + new Date()); // this displays the correct date time
while(someConditionIsTrue)
{
String sDate="";
Date rightNow = null;
SimpleDateFormat formatter=null;
formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); // seems innocent enough...

rightNow = new Date(); // gives me the correct date-time
out.println("2. The time is: " + rightNow); //this works, shows correct local time

sDate = formatter.format(rightNow); // converting to string, this does not work, -15 hours difference
out.println("3. The current time: "+ sDate ); // bad date-time
[code]
I'm running this on Solaris 6


humanum errare est.
achana chan
Ranch Hand

Joined: Jul 29, 2002
Posts: 277
Can someone help?

I got several test results back.
The program runs find on W98, XP2, Linux (RedHat7.1), we get the correct dates. But when we run it on Solaris 2.6 / Java 1.1 the formater.format(rightNow) distorts the date.

This is the test result from a Solaris box:
$ java -classpath . Test3
1. The time is: Mon Nov 01 14:16:31 GMT+08:00 2004
2. The time is: Mon Nov 01 14:16:31 GMT+08:00 2004
3. The current time: 31-10-2004 22:16:31 PST
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unusual date formatting problem