Re: java Date problem
- From: "Big Jim" <noone@xxxxxxxxxxx>
- Date: Mon, 03 Apr 2006 18:02:55 GMT
"Oliver Wong" <owong@xxxxxxxxxxxxxx> wrote in message
news:PTaYf.24742$Ph4.24445@xxxxxxxxxxx
Unfortunately I'm working with an existing DB where this is stored as a
"Big Jim" <noone@xxxxxxxxxxx> wrote in message
news:bYUXf.42223$u31.25744@xxxxxxxxxxxxxxxxxxxxxxx
Hi, I've an app where swing clients run all over the globe and a java
server and sybase DB is in the UK.
The users trype in dates "mm/ydd/yyyy" for a "deal" object and these get
translated to a long, sent to the server and stored in the DB. Any user
in any location can look at the deals in their own client and I want to
make sure they all see the same date, (times aren't important).
I want to store the dates as midnight GMT in the DB (datetime col).
Can anyone give me the standard procedure for this? my current effort
ain't working,
I reckon there's 4 steps: (c = Calendar.getInstance())
In the client:
1.translating from the user entered java.util.Date to the long to send
to the server, currently I'm using:
longDate = d.getTime() + c.get(Calendar.ZONE_OFFSET) +
c.get(Calendar.DST_OFFSET)
Notice that if you do this, midnight GMT might not be on the same day
as the day the user entered in. Let's say I live somewhere where it's
GMT-04:00. Let's say it's Monday, April 3rd, 2006, 21:00. If you "convert"
this to GMT via the addition, you'll get Tuesday, April 4th, 2006, 01:00
store in the DB, i.e. the wrong day.
Rather than storing a date in some particular time zone, why don't you
just store number of seconds elapsed since the Unix epoch? The number of
seconds that has elapsed since a given event does not vary based on time
zones, thus allowing you to avoid this whole mess. You send and receive
these numbers of seconds, and only at the client do you then try to
"render" the value into a locale-specific, time-zone-specific String to be
displayed.
- Oliver
date.
I'm trying to do the next best thing i.e. I do the conversion on the client
as you suggest but I have to store the dates somehow. In effect, by storing
all the dates as GMT I am storing the number of seconds from epoch as you
suggest. It's the conversion to this number of seconds (on the server)
before sending them to the client that's a pain.
However, by taking the zone and DST into account when doing this conversion
at least I'm not limiting my (CORBA) server to being in one location i.e. I
can scale geograpically. It's just disappointing that the java conversion
doesn't seem to work properly (see my later post about timezones)
.
- Follow-Ups:
- Re: java Date problem
- From: Oliver Wong
- Re: java Date problem
- References:
- java Date problem
- From: Big Jim
- Re: java Date problem
- From: Oliver Wong
- java Date problem
- Prev by Date: Re: HardDrive backed ArrayList
- Next by Date: Re: Timezone/DST
- Previous by thread: Re: java Date problem
- Next by thread: Re: java Date problem
- Index(es):
Relevant Pages
|