The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
October 2001



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


date synchronization problem

Posted by Matt Gerrans on November 08, 2001 at 10:19 PM

Okay, I apologize. You are correct -- I shouldn't be such a smartass. Please forgive me.

I'll try to make amends by providing some (hopefully) useful information:

I've tried out what you are talking about with tomcat on a Linux box, connecting to it with two different Windows systems, both with different locale settings. It seems to work as I would expect (it is always the time from the server, with the server's local), so maybe I don't understand what you mean by "running on another machine." Do you mean running the JSP in acontainer (tomcat, or whatever) on another machine, or running the JSP (from the original container/server) in a browser on a different machine?

Also, (and perhaps more importantly) it looks like you may want to use java.util.Calendar, instead of Date. With Calendar, you can initialize it with a particular locale, which may solve your problem. Also, Date has a lot of stuff deprecated in Java 2, so I guess Sun is trying to get people to move to using Calendar.

- mfg

> i've tried ur suggestion.

> 1. i tried parsing the dateString to Date object. It doesn't work. the dateString using the SimpleDateFormat works fine.
> as i parsed it back to the Date object, the date changed without following my time zone. Since i can't i parse it back to the Date object, the getMonth(), getYear().. etc is rendered useless.

> to narrate my point :

> part of code:
> dateString - follows my timeZone

> //parsing dateString back to Date object
> ParsePosition pp = new ParsePosition(0);
> Date date = dateFmt.parse(dateString, pp);

> but 'date' doesn't follow my time zone.

> sample output :
> dateString : 2001-11-08 1216 // my time
> date : Wed Nov 07 12:36:00 PST 2001 //doesn't follow my time

> 2. i couldn't find any method in the Date class that allows direct manipulation to the timeZone. that is, to define the initialized date according to my time zone.

> again, any eccentricity ONLY occurs abberently in JSP.
> everything works perfectly fine in JAVA.

> so master matt? any ideas? :)

> i hope to find a way to evade the 'silly' parseInt() i was using.
> maybe u can help. again, i thank u for ur time.


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us