RadDatetimepicker and timezones

2 posts, 0 answers
  1. mark
    mark avatar
    19 posts
    Member since:
    May 2008

    Posted 22 Apr 2010 Link to this post

    Hi  folks, this is particularly difficult to explain, however I will try by best
    at the moment I have a raddatetimepicker on a page,

    I have a pagemethod that accepts  the value of the raddatetimepicker field and saves it to the database.
    at present I am in New Zealand and the hosted application is on our server in the UK. if I enter in a date of say 23/apr/2010 13:00 the date is saved on the server as 23/apr/2010 01:00.  which I understand and accept.

    However when I go to view the record back on my browser it shows the server time (this is because the date &time is actually bound to the control server side)  . I am sure that if  I save  the record again  that the time on the server will go to 22/apr/20101 13:00

    what is the best way to ensure that times are correct,  I believe that using  UTC format may be the best way to go, but as yet I've not seen a good example for how to use this. or do I  supply the current time zone of the client to the  server and do my calculations there?

    Many Thanks 

    Mark



  2. Radoslav
    Admin
    Radoslav avatar
    1566 posts

    Posted 29 Apr 2010 Link to this post

    Hello Mark,

    This is a difficult issue to deal with.  The problem is that timezone information is not directly available through the web browser.  You could use heuristics to determine the correct time zone or you will have to store the timezone settings for a user based on their selection.  
    You should always store your date/time values in the DB in UTC.  This eliminates many conversion issues.  If you store the information in UTC then you need only translate from UTC to the user's local timezone when you display the data to them and you need to convert from their time zone to UTC when you get date/time values from them. 

    You could use the following steps to convert the DB UTC value to the local user's time zone:
    1) Get the stored timezone value for the user
    2) Create a SimpleTimeZone class to wrap it
    3) Use the SimpleTimeZone.ToLocalTime method to convert the DateTime value to the local time.

    For converting from the user's local timezone to UTC do the reverse:
    1) Get the stored timezone value from the user
    2) Create a SimpleTimeZone class to wrap it
    3) Use SimpleTimeZone.ToUniversalTime method to convert the DateTime to UTC.

    Additionally you could check out the following forum posts which elaborates on the time zones and asp.net:
    http://stackoverflow.com/questions/832986/how-to-work-with-timezone-in-asp-net
    http://weblogs.asp.net/cprieto/archive/2010/01/03/handling-timezone-information-in-asp-net.aspx

    I hope this helps.

    Greetings,
    Radoslav
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top