1

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?

johnstaveley
  • 1,400
  • 1
  • 22
  • 46

2 Answers2

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
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