简体   繁体   中英

What is the best way to handle DateTime in a Web Application?

I've been doing some research around on how to properly store and save the Date and Time in a Web Application but I couldn't find a post that has a marked answer.

I have a ASP.NET MVC website and I use C# for backend code and MS SQL for the database, let say you have different client with different TimeZone currently I'm storing the DateTime by DateTime.UtcNow and I just display it back in "YYYY/MM/DD" format.

All you really need to do is make sure the application server and the database server share the same time settings and are in sync.

IIS, .NET, and SQL Server all use the system time by default.

Clients in different time zones will still use the system time of the IIS server they are connected too. Most sites just format the date on the client side, to the clients zone.

If you want to get fancy, you can write database triggers that handle transaction time stamps. This comes in handy if you do a lot of back-end processing.

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