Probably every web developer has already had topics around time zones. I again had it. I just want to make another notice for the developer community around the globe (and my future me) how I came around this topic now.
In .NET there are two ways to get the time zone (why having only one):
TimeZone.CurrentTimeZone // type System.TimeZone TimeZoneInfo.Local // type System.TimeZoneInfo
The TimeZoneInfo is the newer one satisfying some features required in Vista or something :). With this class one could also convert times into different time zones using the TimeZoneInfo.Id:
// TimeZoneInfo.Local.Id is something like "W. Europe Standard Time" TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.UtcNow, TimeZoneInfo.Local.Id);
Altogether this whole topic is not so nice. It is not so easy to reproduce problems when developing against a local web server. I managed to do a “hacky” workaround:
- Stop the IIS Express processes
- Set local time zone at the taskbar’s clock usually on the bottom right of your desktop – so defining the time zone of the web server
- Start the debugging – this starts a IIS Express for you with your chosen time zone
- Add watch TimeZoneInfo.Local – so that you see what the current time zone is.
You will need it, to be always aware what the current server time zone is. It was also written somewhere that this information is not thread and not even process safe.
- While running the app, change to your favorite client time zone on your clock, so that your browser’s time zone is according to your problem to reproduce
My specific problem was on Kendo grids where binding to a DateTime struct happens automatically by specifying the DateTimeKind…
I know it is hacky – but it’s working – hope I helped someone.