4

Is here a way to change timezone setting for a request, for example, at Application_AcquireRequestState

then for the whole request, no matter when I use Datetime.ToLocalTime (or new Datetime() etc), a local time version will be shown to current user/request?

(or I have to setup timezone for everytime I use ToLocalTime )

Eric Yin
  • 8,737
  • 19
  • 77
  • 118

2 Answers2

0

You need to manage TimeZone info using thread context/storage. There is no 1:1 mapping from Culture to TimeZone (it's a many:many relationship) (Reference Post). There are many ways to do this - such as using a custom ThreadPrincipal with context members or Thread Local Storage (TLS)

Community
  • 1
  • 1
SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
-1

Override InitializeCulture() in your view and set the Thread.CurrentThread.CurrentCulture and Thread.CurrentThread.CurrentUICulture properties to the culture of your choice.

Sjoerd
  • 74,049
  • 16
  • 131
  • 175
  • Do you have some sample code, I already have code on culture, but I do not think culture and timezone are related. – Eric Yin Dec 09 '11 at 08:39
  • You're right, DateTime.ToLocal() does not use the current culture, but [TimeZoneInfo.Local](http://msdn.microsoft.com/en-us/library/system.timezoneinfo.local.aspx). You can not change this value easily. – Sjoerd Dec 09 '11 at 08:52