Re: how to make dates without timezones?



On Feb 21, 11:35 am, Arne Vajhøj <a...@xxxxxxxxxx> wrote:
epicwinter wrote:
On Feb 21, 8:21 am, Arne Vajhøj <a...@xxxxxxxxxx> wrote:
epicwinter wrote:
In my database I have a lot of date fields that aren't time stamps but
just store dates.  The problem is that when i load them into a java
Date it automatically assigns the timezone.  The result will be a date
with 0 hours, 0 minutes, 0 seconds and the time zone of the server.
Like 02/20/2009 00:00:00 CST.
My application is a client server app using rmi.  When the date is
passed to the client through all of the sudden the time zone which was
auto assigned when the date was populated from the server can change
the actual date.   So if on the server I have 02/20/2009 00:00:00 CST
and the client is on pacific time then the date shows as the day
before.  Because that date in pacific standard time is 02/19/2009
23:00:00 PST
So is there a way for all my dates to be completely ignorant of time
zones?
The same time *can* be two different days in two different timezones.

The two most obvious solutions for your requirement to have client
show server date are:
- have the server do the formatting and send String instead of DateTime

This would work but I was really hoping to avoid it, it is a pain to
maintain and just kind of kludgy.  It seems to me that java should
have a date class without time and timezone.  Every database has a
date type and a timestamp type, yet java doesn't support just date
types.  What surprises me more is that this doesn't appear to be a
common issue.

None of the classes java.util.Date, java.sql.Date etc. has
timezone - they basically contains number of milliseconds since
1-Jan-1970 00:00:00 in London.

It is all in the formatting !

- have the client format using the servers timezone

I have tried this too.  It works in some respects but creates new
issues.  There are a few areas where time is pertinent on my
application and in this manner it would always show the client the
wrong time unless they happened to actually be in the same time zone
as the server.

I don't understand that argument.

You can specify timezone for each individual formatting (DateFormat
has a setTimeZone method.

Arne

Arne- I am sorry but I don't understand what you mean by it is just
formatting. In my database i only store a date type that includes
month, day, year. When I load that into a Date class it automatically
assigns the local timezone and i get 02-21-2009 00:00:00 CST or
whatever the time zone is. If that date is then viewed on a client on
PST then it is 02-20-2009 22:00:00 PST. So the date portion shows the
day before.
.



Relevant Pages

  • Re: how to make dates without timezones?
    ... because the time depends on the timezone. ... servers time for both parse and format. ... that letting the client app format using the servers timezone is ... that the bulk of the work in my app is done on the server and is ...
    (comp.lang.java.programmer)
  • Re: Date problem
    ... even what a time zone is. ... time zone of the client, ... As far as I am aware, the browser does not notify the server what ... locale they are in, nor, specifically, what timezone. ...
    (comp.lang.php)
  • Re: how to make dates without timezones?
    ... servers time for both parse and format. ... that letting the client app format using the servers timezone is ... I would store all times on the server as a long in milliseconds since Jan 1, ... You might have to send the client's time zone as a parameter in your RMI request. ...
    (comp.lang.java.programmer)
  • Re: Date problem
    ... time zone of the client, ... As far as I am aware, the browser does not notify the server what ... locale they are in, nor, specifically, what timezone. ... Nor is it possible to know if the time zone setting on the ...
    (comp.lang.php)
  • Re: how to make dates without timezones?
    ... because the time depends on the timezone. ... servers time for both parse and format. ... that letting the client app format using the servers timezone is ... that the bulk of the work in my app is done on the server and is ...
    (comp.lang.java.programmer)