如何使用Moment.js返回当前时间戳? [英] How to return the current timestamp with Moment.js?
问题描述
伙计,
我正在尝试了解MomentJS API。在机器上获取当前时间的合适方法是什么?
I am trying to understand the MomentJS API. What is the appropriate way to get the current time on the machine?
var CurrentDate = moment();
vs
var CurrentDate = moment().format();
尝试解析他们的文档,并且不清楚要使用什么。
Trying to parse their docs, and its not apparent what to use.
http://momentjs.com/docs/ #/ query / is-a-moment /
推荐答案
在这里,您要为CurrentDate分配一个momentjs实例:
Here you are assigning an instance of momentjs to CurrentDate:
var CurrentDate = moment();
这里只是一个字符串,一个来自默认格式的momentjs实例的结果:
Here just a string, the result from default formatting of a momentjs instance:
var CurrentDate = moment().format();
这里是自1月以来的秒数......好吧,unix时间戳:
And here the number of seconds since january of... well, unix timestamp:
var CurrentDate = moment().unix();
此处另一个字符串为ISO 8601( ISO 8601和RFC 3339日期格式之间有什么区别?):
And here another string as ISO 8601 (What's the difference between ISO 8601 and RFC 3339 Date Formats?):
var CurrentDate = moment().toISOString();
这也可以这样做:
var a = moment();
var b = moment(a.toISOString());
console.log(a.isSame(b)); // true
这篇关于如何使用Moment.js返回当前时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!