-
Notifications
You must be signed in to change notification settings - Fork 110
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
ISO-8601 With offset displaying local time #40
Comments
It's an interesting one. These are the steps currently required:
Whenever I've used this / thought about it the time zone to display for was available as an IANA time zone string. In your case it's not, because it's contained in the original date string. I think I won't have time to think about this right now, but if you can figure it out and if necessary propose a PR I'll find time to consider it. |
@marnusw so using the offset worked as intended, but I had to extract it from the ISO String like so import { toDate, format, utcToZonedTime } from 'date-fns-tz';
const isoDateString = '2020-01-09T20:00-05:00';
const dateWithTz = toDate(isoDateString);
const [offset] = isoDateString.match(/(-|\+)([0-9][0-9]):([0-9][0-9])$/);
const timeZonedDate = utcToZonedTime(dateWithTz, offset);
format(timeZonedStartDate, 'eeee, MMMM d, yyyy', { timeZone: offset }) I will close this since it's technically possible, but have to jump through hoops. If there is a better way, would be interested to know it. |
I have been struggling with an ISO 8601 date string that we need to display and perserve the offset (not display it in the users local time). Here is the input in ISO-8601 format-
Source
2020-01-09T20:00-05:00
Formatting
result
06:00 PM - Thursday, January 9, 2020 // my local time
expected
08:00 PM - Thursday, January 9, 2020 // the correct time in the specified offset
Am I missing a step here?
The text was updated successfully, but these errors were encountered: