Got an excel export feature where the datetime column should be localized based on the browser location (14-Nov-2022 12:51 PM EST). Using NodaTime, I am able to localize it. However, I am not able to get the timezone abbreviation (PST, EST, CST etc..,) which needs to be appended at the end of the datetime string.
public static string ToSpecificTimeZone(this DateTimeOffset utcDateTime, int offset)
{
var offsetTimeSpan = TimeSpan.FromMinutes(offset);
var localizedDateTime =
Instant.FromDateTimeOffset(new DateTimeOffset(utcDateTime.DateTime, offsetTimeSpan));
var localizedDateTimeString = localizedDateTime.ToString("dd-MMM-yyyy hh:mm tt", CultureInfo.InvariantCulture);
return localizedDateTimeString;
}
I used this logic to get the zone abbreviation for system default, but dont know how to get it for dynamic offsets,
var zone = DateTimeZoneProviders.Tzdb.GetSystemDefault();
var zonedDateTime = SystemClock.Instance.GetCurrentInstant().InZone(zone);
var zoneName = zonedDateTime.Zone.GetZoneInterval(zonedDateTime.ToInstant()).Name;
Any tips or directions would be really helpful.