4

i've got an globalization setting in the web.config like this:

<globalization culture="de-DE" uiCulture="de-DE" />

and on an average aspx page i output sth. like:

var a = DateTime.UtcNow.ToLocalTime().ToString();
var b = DateTime.UtcNow.ToString();
var c = DateTime.Now.ToLocalTime().ToString();
var d = TimeZone.CurrentTimeZone.ToLocalTime(DateTime.UtcNow).ToString();

Result: The values of a,b,c,d are ALL identical ( e.g. 01.01.2001 17:00:00 ), when i would expect the local and UTC times to be different.

What am i missing here and how can i get the correct localtime from a UTC date.. i checked other topics already, but it didn't work..

abatishchev
  • 98,240
  • 88
  • 296
  • 433
David
  • 2,551
  • 3
  • 34
  • 62

3 Answers3

6

Microsoft Azure is set to have UTC time be the local time no matter where the data center is located. If you want to convert to a time that is local to a user's browser you will need to convert it programatically.

Since Azure is a global service, there really is no local time per se, and to be consistent across all their global data centers, it makes sense to use a standard time.

More information at.

http://michaelcollier.wordpress.com/2010/05/22/hey-azure-what-time-is-it/

Andrew
  • 12,991
  • 15
  • 55
  • 85
John Ptacek
  • 1,886
  • 1
  • 15
  • 20
2

As @John has pointed out you have to do it in the client. If it's a web application you can convert UTC to local time in this way: broken link

Greg Gum
  • 33,478
  • 39
  • 162
  • 233
vtortola
  • 34,709
  • 29
  • 161
  • 263
0

This is what I've found works for me:

   TimeZoneInfo de = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time");
   var localTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, de);

And even though it's W. Europe Standard Time, it still takes into account Summer Time. (I have it working with GMT/BST quite nicely)

I had hoped that ToLocalTime would take into account the CultureUI/Culture globalization settings when converting, but that doesn't seem to be the case.

davewasthere
  • 2,988
  • 2
  • 24
  • 25