Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would the same DateTime value yield different displayed time for different users?

In my ASP.NET application I use code from here to find the build date of the application as UTC. The UTC value read from the assembly file is then formatted as follows:

//DateTime time    
return time.ToString("dd MMM yyyy HH:mm:ss");

Now one user opens the page served by that application and sees

28 сен 2012 04:13:56

and notifies the other user who opens the same page and sees

27 Sep 2012 12:14:32

Both requests are served by the same application deployed to clean Windows Azure VMs from the very same package, so it's surely exactly the same code being run for both users.

Clearly strings are formatted differently because of different localization for requests from different users. One user sees month displayed as Sep and the other sees it as сен (equivalent of Sep in Russian).

Why do the hours differ? Are they also adjusted according to some timezone that depends on localization?

like image 767
sharptooth Avatar asked Sep 28 '12 08:09

sharptooth


1 Answers

The most obvious explanation is that the DateTime values are, in fact, different.

The code you linked uses GetCallingAssembly, and you should note that MSDN says that:

If the method that calls the GetCallingAssembly method is expanded inline by the just-in-time (JIT) compiler, or if its caller is expanded inline, the assembly that is returned by GetCallingAssembly may differ unexpectedly

To debug this, I would start by displaying time.Ticks and time.Kind: if these are identical, you know it's a display problem. If they're different, you need to look at how you're generating the time value.

like image 161
Joe Avatar answered Sep 23 '22 02:09

Joe