MomentJS getting JavaScript Date in UTC

后端 未结 3 1523
春和景丽
春和景丽 2020-12-01 04:26

I am not able to get the JavaScript Date string for MongoDB record via the following. It keeps using my local time.

var utc = moment.utc().valueOf();
console         


        
3条回答
  •  春和景丽
    2020-12-01 04:42

    Or simply:

    Date.now

    From MDN documentation:

    The Date.now() method returns the number of milliseconds elapsed since January 1, 1970

    Available since ECMAScript 5.1

    It's the same as was mentioned above (new Date().getTime()), but more shortcutted version.

提交回复
热议问题