According to multiple postings, Microsoft enabled the ability to use an Application setting - WEBSITE_TIME_ZONE
- to control the timezone of the web server.
To try this, I set this value to "Eastern Standard Time" which is my local time zone.
On an ASP.NET MVC Razor page, I added the following code:
DateTime.Now: @DateTime.Now
DateTimeOffset.Now: @DateTimeOffset.Now
DateTime.UtcNow: @DateTimeOffset.UtcNow
when I ran this last night at 5:10:07pm Eastern Standard Time, it gave the following output:
DateTime.Now: 6/18/2015 5:10:07 PM
DateTimeOffset.Now: 6/18/2015 5:10:07 PM +00:00
DateTime.UtcNow: 6/18/2015 9:10:07 PM
As you can see, the setting correctly allowed DateTime.Now
to return the correct value in my timezone rather than UTC like Azure Websites/Web Apps usually do. DateTime.UtcNow
has always returned the correct value for obvious reasons.
However, DateTimeOffset.Now
returns the local time, but with an offset of +00:00
- almost as if the clock was changed rather than the timezone. This occurs even though the documentation says (emphasis mine):
Gets a DateTimeOffset object that is set to the current date and time on the current computer, with the offset set to the local time's offset from Coordinated Universal Time (UTC).
So what is happening that the WEBSITE_TIME_ZONE
setting impacts DateTime.Now
but it does not impact DateTimeOffset.Now
? And is there any way I can get around that?
As a point of clarification, I don't really want to change the time zone on the server. We are working on a proper timezone independent solution. But I'm still curious why this happens the way it does.
By default, all Azure DevOps organizations and user accounts are set to UTC (Coordinated Universal Time) irrespective of what zones they are hosted in. Even if your organization migrated from an on-premises server to Azure DevOps Services, your timezone is set to UTC time.
By default, on Azure App Service, the time zone is always UTC, but you can change it.
Well for me it works right now. If it is not working make sure you set right value
So I added to app settings in azure app "WEBSITE_TIME_ZONE: E. Europe Standard Time"
and it works.
For those who stumble upon this question. This has been fixed for a long time now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With