开发者

Global change to timezone in application

I have an MVC3 application that is recently published to a web server. This server has a different timezone than mine, and that means DateTime.Now on this server is different from my own. That also means t开发者_开发知识库hat all times shown on the website is shown wrong for me.

The user base for this application all live in the same time zone, so I am looking for a method to override the servers time zone, and use my own timezone instead.

I really don't want to just add or deduct hours based on the difference, since that will get messed up when daylight saving occurs.


You could use something like this to convert the current UTC date/time to your local time:

TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
DateTime localTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, tzi);

Just change the Id passed into TimeZoneInfo.FindSystemTimeZoneById to be your local time zone identifier.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜