Re: java Date problem




"Oliver Wong" <owong@xxxxxxxxxxxxxx> wrote in message
news:PTaYf.24742$Ph4.24445@xxxxxxxxxxx

"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
Unfortunately I'm working with an existing DB where this is stored as a
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)


.



Relevant Pages

  • Re: [opensuse] best file distribution technology for my case?
    ... I googled a lot and found I am outdated: FTP protocol can do encoding conversion. ... So now if Windows user use standard complaint FTP client, they can get the filenames in correct encoding. ... as long as the server is not compromised, the file integrity is not my concern, because other campus services also have this problem for years and they even offering .exe file for downloading, here I only got audio files, I am sure there will not be so much compliance. ...
    (SuSE)
  • Re: What doesnt lend itself to OO?
    ... >> proxy and instructs the server to constuct the real object. ... rather than client code. ... If 'clock' is instantiated in the server, ... > for the server interface at the OOA level. ...
    (comp.object)
  • Re: exchange basics
    ... If you find users switching between client ... > store, so you're right, it wouldn't be a big deal. ... >> -If messages can be stored on server instead of downloading, ... > Exchange can inform and enforce quotas on mail storage. ...
    (microsoft.public.exchange.design)
  • This is going straight to the pool room
    ... or not the client has privilege to do what they're trying to do, ... The server environment is this: ... 3GL User action Routines that Tier3 will execute on your behalf during the ... Routine Name: USER_INIT ...
    (comp.os.vms)
  • [Full-Disclosure] R: Full-Disclosure Digest, Vol 3, Issue 42
    ... Full-Disclosure Digest, Vol 3, Issue 42 ... SD Server 4.0.70 Directory Traversal Bug ... Arkeia Network Backup Client Remote Access ...
    (Full-Disclosure)