How to handle DateTime for an application designed to run around the world. UTC / GTM / Daylight Saving

I am working on an application whose target audience is worldwide. My development platform is the ASP.Net/Sql server, which is currently hosted on the same stand-alone server.

It is possible that Sql Server may be migrated to a different server and web application for hosting on different servers. The time zone may differ for both servers.

We are currently in development and should be working on the concept of Universal Date, rather than fighting at a later stage.

Our database currently has the following column type for date and time.

DateTime (mm / dd / yyyy hh: MM: ss), SmallDateTime (contains only date, mm / dd / yyyy 12:00:00), Varchar (contains hhMMss only in 24-hour format)

Currently, we save the GetDate () of the Sql server , DateTime.Now of C # , i.e. ASP.NET, javascript datetime and any other date directly. There is currently no UTC conversion or anything like that. At the moment, we do not save any TimeZone or any offset.

How to handle DateTime related issues when

  • A stored procedure call to save the DateTime from the user interface to the database

  • Display data from stored procedure in user interface

  • Display data from ASP.NET server for client browser

  • Save data from client browser to ASP.NET server

Please offer some code examples for each of these cases along with the Summer Time function.

+4
source share
1 answer

I work for a company that has a business all over the world, and we save all dates in UTC.

Basically, in your sql you need to use the GETUTCDATE () function instead of GETDATE () and in C # you use DateTime.UtcNow instead of DateTime.Now.

Database fields can be standard datetime

In the user interface, you can display the date in yyyy / MM / dd format if you do not know or cannot determine the local settings of the client.

0
source

Source: https://habr.com/ru/post/1383399/


All Articles