I'm using a javascript snippet to get the timezone name of the user. Here is the snippet
function getTimezoneName() {
const today = new Date();
const short = today.toLocaleDateString(undefined);
const full = today.toLocaleDateString(undefined, { timeZoneName: 'long' });
// Trying to remove date from the string in a locale-agnostic way
const shortIndex = full.indexOf(short);
if (shortIndex >= 0) {
const trimmed = full.substring(0, shortIndex) + full.substring(shortIndex + short.length);
// by this time `trimmed` should be the timezone's name with some punctuation -
// trim it from both sides
return trimmed.replace(/^[\s,.\-:;]+|[\s,.\-:;]+$/g, '');
} else {
// in some magic case when short representation of date is not present in the long one, just return the long one as a fallback, since it should contain the timezone's name
return full;
}
}
console.log(getTimezoneName());
After getting the timezone of the user I am saving it to the database for timezone conversion purposes. This solution was working fine before the "Central Daylight Time" timezone Id. I was taking the user timezone from the database and converting the UTC time to user's timezone using FindSystemTimeZoneById.
Here is my extension method:
public static DateTime ToClientTime(this DateTime dt)
{
var tz = TimeZoneInfo.FindSystemTimeZoneById(HttpContext.Current.User.GetTimeZone());
var tzTime = TimeZoneInfo.ConvertTimeFromUtc(dt, tz);
return tzTime;
}
Now, the issue is javascript snippet is showing me the timezone id "Central Daylight Time" but in the timezones provided list there is no key with this name.
Can anyone provide me the solution for this issue.