moment.js以毫秒为单位获取当前时间? [英] moment.js get current time in milliseconds?

查看:4180
本文介绍了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时间戳

这篇关于moment.js以毫秒为单位获取当前时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆