0

I have deployed my application on AWS Lambda but while getting time zone i am getting this error

'The time zone ID 'Pacific Standard Time' was not found on the local computer.'

How can i add timezones on lambda.

TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(userModel.TimeZoneListCode);
Backs
  • 24,430
  • 5
  • 58
  • 85
Hanan Afzal
  • 21
  • 1
  • 4
  • 1
    Which version of .NET are you using? "Pacific Standard Time" is a Windows time zone database ID; the corresponding IANA one would be America/Los_Angeles. I would generally encourage you to use IANA IDs everywhere, but in .NET 6 you should be able to use either style on every platform. – Jon Skeet Sep 12 '22 at 09:30
  • 1
    @JonSkeet The TimeZoneInfo.FindSystemTimeZoneById(string) method automatically accepts either Windows or IANA time zones on either platform and converts them if needed. – Hanan Afzal Sep 12 '22 at 09:55
  • 2
    Yes, it does *in .NET 6*. It doesn't in older versions, which is why I was asking what version of .NET you're using. If you're using .NET Core 3.1, that would explain the problem, for example. – Jon Skeet Sep 12 '22 at 11:07
  • 1
    Also, the conversions in .NET 6 only work if ICU data is available (either pre-installed, or app-local ICU). I'm not sure if AWS Lambda has ICU or not, TBH. If not, you can use `America/Los_Angeles`, or if necessary you can do the conversions with [timezoneconverter](https://github.com/mattjohnsonpint/TimeZoneConverter). – Matt Johnson-Pint Sep 12 '22 at 21:24

1 Answers1

4

In general, if Windows time zones like this don't work:

TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");

... then you're not running on Windows and either you're not using .NET 6 or higher, or you don't have ICU data available in your environment. Either way, you should be able to use IANA time zones:

TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("America/Los_Angeles");

Alternatively, you can use TimeZoneConverter to work with either form:

TimeZoneInfo tzi = TZConvert.GetTimeZoneInfo("Pacific Standard Time");

or

TimeZoneInfo tzi = TZConvert.GetTimeZoneInfo("America/Los_Angeles");
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
  • 1
    As an FYI for anyone experiencing an issue like this on Windows Server 2019 or later, it looks like you must have .NET 7 or higher in order for the ICU data to be available by default: [ICU on Windows Server](https://learn.microsoft.com/en-us/dotnet/core/compatibility/globalization/7.0/icu-globalization-api). Or you could build your app with the app-local ICU option. – Ben.12 Mar 13 '23 at 23:51