最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Extract local time and timezone offset information using date-fns - Stack Overflow

programmeradmin1浏览0评论

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 badges
Add a ment  | 

3 Answers 3

Reset to default 2

I think you should look from date-fns-tz.

Check the method (utcToZonedTime, getTimezoneOffset).

Hope this help

发布评论

评论列表(0)

  1. 暂无评论