aspose file tools*
The moose likes JSP and the fly likes Convert from Server UTC  timezone to Client timezone Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Convert from Server UTC  timezone to Client timezone" Watch "Convert from Server UTC  timezone to Client timezone" New topic
Author

Convert from Server UTC timezone to Client timezone

perumal mani
Greenhorn

Joined: May 27, 2008
Posts: 5
Hi,
I want to send the time information from server to the client. server timezone will be in UTC(GMT). i need to convert the server time from UTC to the time zone which is set in the client machine in jsp and need to display it in the webpage. how to do this?
i am struggling lot with this. please let me know the answers. Thanks in advance. Hopefully waiting for the replies.

Thanks & Regards,
Perumal M
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29237
    
139

Perumal,
I don't think you can get the client timezone without passing it as a parameter from the client. You could output the time in a generic format (like UTC) and use JavaScript to output it in local time on the client.

You might want to take a look at how JavaRanch solved the problem. Ignore the part about parsing Colorado time and daylight savings time. We were trying to avoid changing the logic to output server time since it is so entrenched in the code base.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Rowan Sylvester-Bradley
Greenhorn

Joined: Sep 18, 2008
Posts: 1
I have a similar problem. I have a mySQL database on my web server which is somewhere in the USA. In this database I record the dates and times of certain events, such as when people log in, or download certain files. At a later date I want to display these dates and times to a user using a web browser, who will be in UK or possibly anywhere else in the world.

It seems to me that the timezone of the _server_ should not be used - this simply complicates things, such as what if my web site is relocated to a server in a different timezone etc. So all dates and times should be stored in the database as UTC (or Unix timestamps).

It also seems to me that it's a big waste of effort to convert the times and dates from the database to local time on the server, since this means (a) I have to know which timezone the user is in, and (b) the server has to have complete knowledge of how to convert any time and date from UTC to any timezone in the world. It is surely better to transmit the UTC value to the client, and to have the client, which should know where it is, and which timezone applies, and what the rules are, convert to local time.

I will also sometimes need to convert local time and dates entered by the user into UTC so they can be netered into the database - logically this should also happen on the client.

Complications, which don't often appear in articles on this topic, include:
- the localisation of the time may alter the date (including the year), i.e. 1-Jan-2008 02:00:00 UTC is 31-Dec-2007 21:00:00 EST
- the localisation needs to know about leap years, including the special handling of century years (i.e. 1800, 1900 and 2100 are not leap years; 2000 is). This is because localising a time on 28-Feb may move the date to 29-Feb or 1-Mar (or vice versa).
- I don't want just to display the time _now_ in local time; I want to be able to display historical and future times and dates correctly localised. This means that the code has to know if and when DST came into force and ceased in each historical and future year, as well as any changes in the rules about when DST starts and stops.

Does anyone have a good solution to this problem?

I'm not quite sure what the best solution is for users who have scripts disabled.

Thanks - Rowan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Convert from Server UTC timezone to Client timezone
 
Similar Threads
Java Date problem
How to get client machine timeZone
Timezone related datetime conversion problem
maintaining proper UTC date/time in javascript
Timezone offset to Timezone ID conversion