momentjs toDate() - timezone gets reset

匿名 (未验证) 提交于 2019-12-03 02:59:02

问题:

I am working with momentjs and converting dates to different time zones using convertedDate = moment().utcOffset(timezone).format(). This works well but it is a string and I need to transform it to date object.

I've tried new Date(convertedDate) and moment().utcOffset(timezone).toDate() but that returns my current timezone as a date object. How can I keep the converted timezone?

回答1:

So I wasn't very far off. The format needs to exclude timezone for it to work. This code finally worked how I needed it to.

convertedDate = new Date(moment().utcOffset('-4').format('YYYY-MM-DD HH:mm'));



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!