简体   繁体   English

在Web应用程序中处理DateTime的最佳方法是什么?

[英]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. 我一直在研究如何在Web应用程序中正确存储和保存日期和时间,但我找不到一个有明显答案的帖子。

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. 我有一个ASP.NET MVC网站,我使用C#作为数据库的后端代码和MS SQL,假设你有不同的TimeZone客户端,我正在通过DateTime.UtcNow存储DateTime,我只是将它显示在“ YYYY / MM / DD“格式。

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. 默认情况下,IIS,.NET和SQL Server都使用系统时间。

Clients in different time zones will still use the system time of the IIS server they are connected too. 不同时区的客户端仍将使用它们所连接的IIS服务器的系统时间。 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. 如果您进行大量后端处理,这会派上用场。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Web API Razor中处理视图路由的最佳方法是什么 - What is the best way to handle the view routing in Web API Razor 从Web应用程序中记录某人的最佳方法是什么? - What is the best way to log someone out of a web application? 在C#Web应用程序中实现通知的最佳方法是什么? - What is the best way to implement notification in a C# web application? 从Web应用程序创建锁的最佳方法是什么? - What is the best way to create a lock from a web application? 在Web应用程序中获取构建信息的最佳方法是什么? - What is the best way to get Build Info in a Web application? 将DateTime存储到cookie中的最佳方法是什么? - What is the best way to store DateTime into cookies? 在web.config的mailSettings部分中处理多个邮件服务器的最佳方法是什么? - What is the best way to handle multiple mail servers in the mailSettings section of the web.config? 在ASP.Net中处理web.config文件版本的最佳方法是什么? - What's the best way to handle web.config file versions in ASP.Net? 在 Blazor 服务器端应用程序中处理不同浏览器功能的最佳方法是什么? - What is the best way to handle different browser features within a Blazor Server-Side Application? 处理“未找到应用程序”等特定 Win32 异常的最佳方法是什么? - What is the best way to handle a specific Win32 Exception like "application not found"?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM