Forums Register Login
Unusual date formatting problem
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.
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
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
I'm running this on Solaris 6
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
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards

All times above are in ranch (not your local) time.
The current ranch time is
Nov 19, 2017 07:49:14.