0

I have deployed my asp.net core application in azure linux. I am trying to convert UTC time to 'Central Europe Standard Time'. But, I am getting the following exception. In my local no issues, but I am getting issue after deployment.

The time zone ID 'Central Europe Standard Time' was not found on the local computer. Could not find file '/usr/share/zoneinfo/Central Europe Standard Time'.

TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById("Central Europe Standard Time");
   var cstTime = TimeZoneInfo.ConvertTimeFromUtc(utcDateTime, cstZone);
Jeeva J
  • 3,173
  • 10
  • 38
  • 85

2 Answers2

2

For the App Services that run on Linux, you should use Time Zone values from the IANA TZ database.

In your case Time Zone Central Europe Standard Time in linux could be Europe/Amsterdam

https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

https://learn.microsoft.com/en-us/azure/app-service/faq-configuration-and-management#how-do-i-set-the-server-time-zone-for-my-web-app

Andriy Bilous
  • 2,337
  • 1
  • 5
  • 16
  • Thank you for your answer. Yes, your answer is right. I have used the following to convert datetime. https://github.com/mattjohnsonpint/TimeZoneConverter – Jeeva J Apr 19 '21 at 12:58
1

Linux and Windows store timzones differently (see for example TimeZoneInfo in .NET Core when hosting on unix (nginx)).

One solution is to examine what is available and choose appropriately like shown at How to get TimeZoneInfo on Windows and Linux from www.ankursheel.com:

var nzTimeZone = TimeZoneInfo.GetSystemTimeZones().Any(x => x.Id == "New Zealand Standard Time")
   ? TimeZoneInfo.FindSystemTimeZoneById("New Zealand Standard Time")
   : TimeZoneInfo.FindSystemTimeZoneById("Pacific/Auckland");
tymtam
  • 31,798
  • 8
  • 86
  • 126
  • Thank you for your answer. Yes, your answer is right. I have used the following to convert datetime. https://github.com/mattjohnsonpint/TimeZoneConverter – Jeeva J Apr 19 '21 at 12:58