moment.js以毫秒为单位获取当前时间?

问题描述:

var timeArr = moment().format('HH:mm:ss').split(':');

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

此解决方案有效,测试它,但我宁愿只使用时刻api而不是使用我的自己的代码。

This solution works, test it, but I'd rather just use the moment api instead of using my own code.

此代码以毫秒为单位返回TODAYS时间。我需要它在几毫秒内调用另一个函数...不能使用纪元。今天的时间需要以毫秒为单位。上午9:00 = 3.24e + 7毫秒9:00 pm = 6.84e + 7毫秒。

This code returns TODAYS time in milliseconds. I need it to call another function in milliseconds...Can not use the epoch. Need today's time formated in milliseconds. 9:00am = 3.24e+7 milliseconds 9:00pm = 6.84e+7 milliseconds.

来自文档:
http://momentjs.com/docs/#/parsing/unix-timestamp-milliseconds/

所以:


  • 时刻(...)。valueOf()

  • 解析预先存在的日期并将表示转换为unix时间戳


  • moment()。valueOf()

  • 表示当前的unix时间戳