• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Convert from Server UTC timezone to Client timezone

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author & internet detective
Posts: 42003
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
If you are using a rototiller, you are doing it wrong. Even on this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic