I am running a website in IIS on my local PC, I save a date as UTC and call .ToLocalTime() on it in the front end mvc website. If I run the website on my local PC it outputs the correct date and time adjusted for DST. If I run it in Azure in region UK West I get 1 hour behind. This hasn't been an issue until today i.e. the clocks changed on Saturday. Do I need to raise a ticket with Azure? Or am I doing it wrong?
Asked
Active
Viewed 1,492 times
1
-
If it is helpful, please mark it as answer that will help more communities. – Tom Sun - MSFT Mar 30 '17 at 07:00
2 Answers
1
Azure App server is using UTC time. If your site is not global just for UK. We can use the following code to get the UK local time.
DateTime utcNow = DateTime.UtcNow;
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time"); //UK time zone
DateTimeOffset time = TimeZoneInfo.ConvertTimeFromUtc(utcNow, tz);
lab_time.Text = time.DateTime.ToString(CultureInfo.InvariantCulture); //display the datetime with label.
If your website is to be global that you may need to use javascrpt to do that, more detail please refer to another SO Thread.

Community
- 1
- 1

Tom Sun - MSFT
- 24,161
- 3
- 30
- 47
-
Yes, site is UK only, is there anyway I can set it globally for the entire application? – johnstaveley Mar 29 '17 at 09:16
-
As I mentioned that we need to use javascript to do that. Based on my experience, we can't get the globally local timezone from the server backend. – Tom Sun - MSFT Mar 29 '17 at 09:30
0
Time-zone depends on the the server location literally.
I had faced the same issue. I had my server in Singapore and it used to clash with my zone, India.
It would affect the time and date formats too.
So, Better not use
the ToLocalTime()
at the server
side. just get the UTC time from the server
and convert to
whatever local time at the client
side. Issue resolved!
Hope this helps. Thank you.

Prashanth Benny
- 1,523
- 21
- 33
-
-
But when the time changes, I have no idea what they do at Azure. And, if your website is to be global, it would be a problem! – Prashanth Benny Mar 27 '17 at 08:58
-
Actually I am not sure this is true. My UK Azure instance runs in utc and my qa and production servers (both in UK) run in GMT so server location isn't the issue – johnstaveley Mar 30 '17 at 10:43