使用Moment.js获取当前的unixtimestamp [英] Getting current unixtimestamp using Moment.js

查看:326
本文介绍了使用Moment.js获取当前的unixtimestamp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Moment.js获得Unix时间戳. 我可以在moment.js中找到许多将时间戳转换为日期的函数. 我知道我可以使用以下JavaScript函数轻松获取unix时间戳:Math.floor(new Date().getTime()/1000).

I want to get the Unix TimeStamp using Moment.js. I can find many functions which convert timestamp to date in moment.js. I know that I can easily get the unix timestamp by using the following JavaScript function: Math.floor(new Date().getTime()/1000).

但是我想使用Moment.js来获得相同的结果. moment.js中是否有任何直接函数来获取当前时间戳?

But I want to use Moment.js to get the same result. Is there any direct function in moment.js to get the current timestamp?

推荐答案

要在几秒钟内找到Unix时间戳:

To find the Unix Timestamp in seconds:

moment().unix()

文档是您的朋友. :)

这篇关于使用Moment.js获取当前的unixtimestamp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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