伙计们,
我正在尝试理解MomentJS API。获取机器上当前时间的适当方法是什么?
var CurrentDate = moment();
vs
var CurrentDate = moment().format();
试图解析他们的文档,它不明显使用什么。
http://momentjs.com/docs/#/query/is-a-moment/
伙计们,
我正在尝试理解MomentJS API。获取机器上当前时间的适当方法是什么?
var CurrentDate = moment();
vs
var CurrentDate = moment().format();
试图解析他们的文档,它不明显使用什么。
http://momentjs.com/docs/#/query/is-a-moment/
当前回答
试试这个
console.log(moment().format("MM ddd, YYYY HH:mm:ss a"));
console.log(时刻)。format("MM ddd, YYYY hh: MM:ss a")); < script src = " https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment.min.js " > < /脚本>
其他回答
仍然没有回答。 js -可以做任何事情,但这样一个简单的任务。
我用这个:
moment().toDate().getTime()
要使用am / pm和moment,下面是一个react组件的代码片段
import Moment from 'moment';
const time = Moment().format("hh:mm a")
作为参考,请记住Moment.js被认为是一个遗留项目,可能会带来性能开销
试试这个
console.log(moment().format("MM ddd, YYYY HH:mm:ss a"));
console.log(时刻)。format("MM ddd, YYYY hh: MM:ss a")); < script src = " https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment.min.js " > < /脚本>
当前日期使用moment .js,格式为DD-MM-YYYY
const currentdate=moment().format("DD-MM-YYYY");
console.log(currentdate)
如果您只想要从01-JAN-1970年开始的毫秒数,那么您可以使用
var theMoment = moment(); // or whatever your moment instance is
var millis;
millis = +theMoment; // a short but not very readable form
// or
millis = theMoment.valueOf();
// or (almost sure not as efficient as above)
millis = theMoment.toDate().getTime();