I have the following date
string: 2022-04-16T18:31:00+02:00
and I would like to extract the local time i.e. 2022-04-16T18:31
and offset information +2:00
or 2
using date-fns
.
I know I can do it with a simple string manipulation like this:
const [dateTime, offset] = "2022-04-16T18:31:00+02:00".split('+')
However, if possible, I would like to avoid string manipulation and use the library instead.
I have the following date
string: 2022-04-16T18:31:00+02:00
and I would like to extract the local time i.e. 2022-04-16T18:31
and offset information +2:00
or 2
using date-fns
.
I know I can do it with a simple string manipulation like this:
const [dateTime, offset] = "2022-04-16T18:31:00+02:00".split('+')
However, if possible, I would like to avoid string manipulation and use the library instead.
Share Improve this question asked Apr 29, 2022 at 13:35 JacobdoJacobdo 2,0333 gold badges24 silver badges42 bronze badges3 Answers
Reset to default 2I think you should look from date-fns-tz.
Check the method (utcToZonedTime, getTimezoneOffset).
Hope this help