Ignoring timezones when creating a date in javascript/momentjs

后端 未结 2 2086
刺人心
刺人心 2020-12-23 18:58

I am creating a schedule for something on the east coast, and I need to create a date that always returns a date object/timestamp for this time.

So, if I open the pa

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-23 19:26

    You can do this with moment.js using moment.utc().

    http://momentjs.com/docs/#/parsing/utc/

    moment([2011, 10, 8, 5]).format(); // different output based on timezone
    moment.utc([2011, 10, 8, 5]).format(); // same output for all timezones
    

    The way moment.utc works is by setting a flag internally to use getUTCMinutes instead of getMinutes, thus the output is the same in all timezones.

提交回复
热议问题