Any way to parse a time string using Moment.js but ignore timezone info?

前端 未结 10 1562
深忆病人
深忆病人 2020-12-30 01:56

Given the volume of Timezone questions, I would have thought to be able to find the answer to this issue, but haven\'t had any success.

Is there a way using mo

10条回答
  •  别那么骄傲
    2020-12-30 02:15

    You can ignore the browser's timezone completely by creating a new moment using moment.utc() instead of moment().

    For example, if you are trying to work purely with a UTC date/time of the browser's current time but want to discard its timezone data, you can recreate the browser's current time into a UTC format using the following:

    let nowWithTimezone = moment();
    let nowInUtc = moment.utc(nowWithTimezone.format('MM/DD/YYYY HH:mm'), 'MM/DD/YYYY HH:mm');
    

    Further documentation on moment.utc(): https://momentjs.com/docs/#/parsing/utc/

提交回复
热议问题