开发者

How to handle time difference in ASP.Net (MVC)?

开发者 https://www.devze.com 2022-12-17 03:10 出处:网络
I\'ve published a web application to a server in the USA. The app is actually for swedes (people in Sweden) and I am lookin开发者_开发知识库g for the best way to hadle the time difference.

I've published a web application to a server in the USA. The app is actually for swedes (people in Sweden) and I am lookin开发者_开发知识库g for the best way to hadle the time difference.

There's a +7 hour difference.

Should I store the DateTime.Now in DB as it is, or should I use DateDiff to change the time before creating each record?

What's the best practice here? What to store in the database? Should the date only be differed when presenting it?

Best practices, please!


I usualy store the DateTime.UtcNow which is the utc time. So when it's 13.00 in UTC, it's 14.00 in Sweden and 7.00 in the USA, you store the UTC time (13.00) and you can always format the datetime with a New CultureInfo("sv-SE") to the local time in Sweden, the USA etc.

Michel

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号