moment.js get current time in milliseconds?

前端 未结 7 1132
旧巷少年郎
旧巷少年郎 2021-02-01 11:54
var timeArr = moment().format(\'HH:mm:ss\').split(\':\');

var timeInMilliseconds = (timeArr[0] * 3600000) + (timeArr[1] * 60000);

This solution works,

7条回答
  •  温柔的废话
    2021-02-01 12:18

    You could subtract the current time stamp from 12 AM of the same day.

    Using current timestamp:

    moment().valueOf() - moment().startOf('day').valueOf()
    

    Using arbitrary day:

    moment(someDate).valueOf() - moment(someDate).startOf('day').valueOf()
    

提交回复
热议问题