Reputation: 60684
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 that 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.
Upvotes: 0
Views: 4598
Reputation: 82096
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.
Upvotes: 2