美文网首页
vue中使用moment.js

vue中使用moment.js

作者: SY | 来源:发表于2021-10-12 09:49 被阅读0次

1.先安装  npm install moment

2.在使用的组件里面引入  var moment = require('moment');

moment().format();
//官网    http://momentjs.cn/docs/#/parsing/

3.将时间戳转为标准日期
let day2 = moment(1632983439000).format("YYYY-MM-DD");

    console.log(day2);

或者转为带T的格式等等

4.再将标准日期转为时间戳

 let day3 = moment(day2).valueOf();

    console.log(day3);
5.默认情况下,moment 会解析并以本地时间显示。

如果要解析或以 UTC 显示 moment,则可以使用 moment.utc() 而不是 moment()。
moment().format(); // 2013-02-04T10:35:24-08:00

moment.utc().format(); // 2013-02-04T18:35:24+00:00
重要的是要注意,尽管上面的显示有所不同,但它们在同一时间都是相同的 moment。

vara = moment();varb = moment.utc();a.format();// 2013-02-04T10:35:24-08:00b.format();// 2013-02-04T18:35:24+00:00a.valueOf();// 1360002924000b.valueOf();// 1360002924000

使用 moment.utc() 创建的任何 moment 都将会处于 UTC 模式中,而使用 moment() 创建的任何 moment 则不会。

相关文章

网友评论

      本文标题:vue中使用moment.js

      本文链接:https://www.haomeiwen.com/subject/xsrdoltx.html