-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get TimeZone abbreviation? #14
Comments
+1 |
This isn't the most elegant solution, but you can do it with the native export const getShortTimezoneName = (date: Date): string => {
const timezoneDateStr = date.toLocaleString('en-US', {
timeZoneName: 'short',
});
const timezoneName = timezoneDateStr.split(' ').pop();
if (!timezoneName) {
throw new Error('Could not parse timezone name');
}
return timezoneName;
}; This only works with Like I said, it's not the most elegant, but I've used it for a while with good success. Plus it will be timezone aware for EDT vs EST and PDT vs PST. |
With native JS: new Intl.DateTimeFormat("en-US", {
timeZone: 'America/New_York',
timeZoneName: "short",
})
.formatToParts(new Date())
.find((part) => part.type === "timeZoneName").value; Note that you will see different results with different locales (e.g. |
Is there a way to get the abbreviation of the current timezone? And specifically, how to determine if in daylight saving? (e.g. EDT or EST)
thanks
The text was updated successfully, but these errors were encountered: