Imran Rizvi
Imran Rizvi

Reputation: 7438

Cross platform DateTimeOffset conversion to CST Time Zone

I've written the following code to convert the DateTimeOffset to CST DateTime

var bookingDateInCst = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(itemRequest.BookingDate, "Central Standard Time");

This works on my local machine, but when I deployed it on PCF cloud environment I get the following error "The time zone ID 'Central Standard Time' was not found on the local computer."

How to fix it?

Upvotes: 0

Views: 498

Answers (1)

Imran Rizvi
Imran Rizvi

Reputation: 7438

I've used TZConvert utility, by reading this block

https://devblogs.microsoft.com/dotnet/cross-platform-time-zones-with-net-core/

It helped me fix the issue using following code:

var cstTimeZoneInfo = TZConvert.GetTimeZoneInfo("Central Standard Time");
var bookingDateInCst =TimeZoneInfo.ConvertTimeFromUtc(itemRequest.BookingDate.UtcDateTime, cstTimeZoneInfo);

Upvotes: 1

Related Questions