C# and Current Local time for different countries

牧云@^-^@ 提交于 2019-12-04 05:05:57
Dan Hunex

Save your time in your server using UTC time (DateTime.UtcNow) and then depending on the users time zone you will change this utc time. Never save local time in the db

Just look at the TimeZoneInfo class. You should be able to convert to and from local to server time through there while maintaining DST (Daylight Savings time).

DateTimeOffset newTime = TimeZoneInfo.ConvertTime(DateTimeOffset.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("AppTimeZone"));

You can also find an Open Source Time Zone Implementation by one of the Great Jon Skeet Noda Time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!