3

We are based in the UK and have a series of web services deployed to Azure. One of these automatically refreshes every 5 minutes and displays a 'Last refreshed at hh:mm:ss' message. It appears that this is not taking into account daylight saving time as the time displayed is one hour behind local time. We suspect it is using UTC. We have tried setting

<globalization uiCulture="en" culture="en-GB"/> 

in the web.config and programatically with no success. Is there an easier solution to display the correct local time than having to determine the DST offset and applying it at every instance of 'DateTime.Now()?'

Thanks in advance for any help.

Chris Manners
  • 31
  • 1
  • 1
  • 2

4 Answers4

3

In the Azure Portal under Application Settings add a environmental variable with the name WEBSITE_TIME_ZONE with the value W. Europe Standard Time.

enter image description here

For other values, see: https://msdn.microsoft.com/en-us/library/ms912391(v=winembedded.11).aspx

Fred
  • 12,086
  • 7
  • 60
  • 83
  • 8
    This does not affect the Culture. Only the time zone. The Culture on a WebApp cannot be changed, no matter what you do. It is fixed to en-US. Extra effort is required to ensure your app parses all date time strings as the culture you intend in code. – Microsoft Developer Jun 03 '19 at 13:28
2

@viperguynaz is correct, all of Azure runs on UTC. If you're running in Azure, then you should keep it running in UTC and not try to circumvent it as some things don't behave very nicely then. Instead, as a software developer, you should add the ability into your application to honor time zones and to handle data saved as and services running on UTC. Never use DateTime.Now but instead always use DateTime.UtcNow.

For more info on this, see this question.

Community
  • 1
  • 1
Jaxidian
  • 13,081
  • 8
  • 83
  • 125
1

Yes - Azure runs on UTC time. Read DateTime.ToLocalTime Method and TimeZoneInfo.ConvertTime Method for how to get the local time with time zone known.

viperguynaz
  • 12,044
  • 4
  • 30
  • 41
0

We have a similar UK specific situation and we simply set the timezone using the timezone utility tzutil within a single line "elevated simple" startup task:

tzutil /s "GMT Standard Time"

We haven't seen any issues with this and the timestamps always match our expectations. This seems simpler than ensuring that every DateTime interaction in code is made local time / timezone aware.

I believe that this utility is only included in images of Windows Server 2008 R2 and beyond.

Andy Milligan
  • 400
  • 4
  • 10