This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Unusual date formatting problem  RSS feed

 
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!