I have an MVC3 application the displays the current time locally, but displays the servers time when uploaded to hosting. Is there any way in the app.config or the web.config that I can set my local time to display once my app is uploaded to the server?
UPDATE:I'm looking for a way to do this globally without going back and changing the code for every time I reference DateTime. It seems a little impractical to not be able to set the time for the application globally.
set timezone information in the web.config and convert your time according to the web.config's timezone.
DateTime timeUtc = DateTime.UtcNow;
TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById(timezoneid); // timezoneid from web.config
DateTime cstTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, cstZone);
cstTime is what you want.
来源:https://stackoverflow.com/questions/12255670/is-there-a-way-to-set-the-local-time-which-may-be-different-than-the-servers-t