简体   繁体   中英

windows azure adds +10 hours to time field

We have an asp.net mvc application that is hosted on windows azure as a cloud service. We are having an issue when storing date time.

The site uses telerik controls.

Basically we have a start datetime field and an end datetime field that we enter in a pop-up dialog. If I enter in to this field for example 31/08/2013 06:00 AM for the start and 31/08/2013 07:00 AM for the end then press save it displays in a telerik grid, but it has added 10 hours to each field, I am presuming because Brisbane Australia, where I am is + 10 hours.

I then save the data and it stores in the database as the time that has + 10 hours. The time being entered is not relevant to a time zone we just want whatever time entered to be the time entered, regardless of where the user is etc.

Windows Azure datacenters run in UTC time zone . That's the reason (and as you have guessed) you see a 10 hour time difference. One possible (and recommended) solution could be to make us e of UTC times always in your application. That way no matter from where your application is accessed, you get a consistent behavior in your application as far as date/time is concerned. In this scenario when the user enters any date/time you assume that to be in UTC.

Another thing you could do is pass the user's time zone to your server side logic and convert the date/time provided by the user into UTC time zone. So if a user from Australia provides a start date/time of 31/08/2013 06:00 AM, you also pass the timezone user is in and on the server side you would convert this date/time to UTC based on user's provided date/time and user's time zone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM