Re: how to make dates without timezones?





"epicwinter" <epicwinter@xxxxxxxxxxx> wrote in message news:710cd1cd-5ce3-4ce1-8692-e94ee449766e@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Feb 21, 5:37 pm, Arne Vajhøj <a...@xxxxxxxxxx> wrote:
epicwinter wrote:
> I truly understand what you are saying and I do appreciate all
> your responses. The java time stuff makes perfectly good sense from a
> academic point of view. However in the real world we use dates that
> are completely ignorant of timezones and times. The most obvious
> example is the birthdate field. There are so many applications that
> require the birthdate field as a security token or just for
> demographics verification and display. And even though my birthdate
> might fall on a different day in the Tanzania time zone, if a program
> is validating a birthdate in MM/DD/YYYY and I put in the tanzania
> timezone date it won't validate. So it seems to me that there should
> be a built in java Date class that only stores month date year. I am
> guessing this is contradictory to basing time as milliseconds since
> epoch.

It is correct that a specific birthday is not a specific time,
because the time depends on the timezone.

But for most apps that is handled very simply by using the
servers time for both parse and format. It gives perfectly
consistent results from the user perspective no matter
whether the time stored is actually part of the users
birthday in his timezone.

Your problem arise because you have distributed app. But I still
that letting the client app format using the servers timezone is
the solution. That is work, but distributed apps tend to be work.

Arne

Well I just tried setting it up so my server would auto switch back
and forth between the client's time zones. So for each RMI request
the server says where is this client coming from and then calls
TimeZone.setDefault.

Yikes! I would not do this. I would store all times on the server as a long in milliseconds since Jan 1, 1970 UTC. Then I would use java.text.DateFormat set to the client's local time to format the date on the server, or allow the client to format the date at their end. You might have to send the client's time zone as a parameter in your RMI request.

Unfortunately i couldn't get that to work because it doesn't seem to
be thread safe. It changes it for the entired java virtual machine
and then if another client makes a call from a different timezone it
will switch the timezone for all the client requests. I thought this
would be a winner...frustrating.

If you format the date at the server end, you certainly don't want to be changing the server's time zone all the time. Leave it at the correct time zone for the server, and use the client's time zone to format the date for them. If the client sends their time zone as a parameter in the RMI request to use with java.text.DateFormat, then it will be a local variable that is inherently thread-safe.

The problem I have with just formatting the data on the client side is
that the bulk of the work in my app is done on the server and is
served up to the client. So reports and such are generated in the
server and end up having the timezone of the server.

Yup, just format the report using the client's locale. Have the client send you their locale when they make the request. BTW, sending a locale is even more general than sending a time zone. If you follow that pattern, Java will generate locale-appropriate number formats, time/date formats automagically. And if you use resource bundles to translate strings, you'll get the right language translations too.

.



Relevant Pages

  • Re: how to make dates without timezones?
    ... class, with a unique format on the wire, so that you don't accidentally ... after on a change in timezone. ... access/display the date it is in the same timezone that the server is ... No, make sure it is *always* treated as a specific time zone, regardless ...
    (comp.lang.java.programmer)
  • 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: Meeting Requests accross Time-zones(CST-EST) 2 hours apart
    ... time zone or DST setting on the client or server. ... We do believe we have patched all clients, OS, and server applications, ...
    (microsoft.public.exchange.admin)
  • Re: timezone missing for ftp transfers...
    ... >> FTP server have the wrong time when they are saved to ... What is the client that is in use here? ... >local time zone of the server - which means that they are ...
    (microsoft.public.inetserver.iis.ftp)
  • 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)

Loading