MomentJS/Date object UTC by default

后端 未结 2 1210
清歌不尽
清歌不尽 2021-01-14 05:06

I am using MomentJS in my angular project and i\'m having a lot of issues with different date timezones.

My app should not take into consideration any timezones, how

2条回答
  •  醉话见心
    2021-01-14 05:26

    you can try to use moment in UTC mode in this way:

    let m = moment().utc()

    then, to reset the time to midnight of that day you can call this method:

    m.startOf('day')

    you can also chain it all together:

    let m = moment.utc().startOf('day')

    and if you print it it will be something like:

    console.log(m.format())
    // 2019-07-02T00:00:00Z
    

    You can also do it with the native Date, but you'll have to write a bunch of code that momentjs already has...

    I hope this answer your questions!

    for reference have a look here: https://momentjs.com/docs/#/parsing/utc/

    and here: https://momentjs.com/docs/#/manipulating/start-of/

提交回复
热议问题