博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
强大的时间库moment.js常用方法
阅读量:7079 次
发布时间:2019-06-28

本文共 1756 字,大约阅读时间需要 5 分钟。

  hot3.png

日期格式化

moment().format('MMMM Do YYYY, h:mm:ss a'); // 九月 3日 2015, 3:45:43 下午moment().format('dddd');                    // 星期四moment().format("MMM Do YY");               // 9月 3日 15moment().format('YYYY [escaped] YYYY');     // 2015 escaped 2015moment().format();                          // 2015-09-03T15:45:43+08:00

相对时间

moment("20111031", "YYYYMMDD").fromNow(); // 4 年前moment("20120620", "YYYYMMDD").fromNow(); // 3 年前moment().startOf('day').fromNow();        // 16 小时前moment().endOf('day').fromNow();          // 8 小时内moment().startOf('hour').fromNow();       // 1 小时前

日历时间

moment().subtract(10, 'days').calendar(); // 2015年8月24日moment().subtract(6, 'days').calendar();  // 上周五下午3点45moment().subtract(3, 'days').calendar();  // 本周一下午3点45moment().subtract(1, 'days').calendar();  // 昨天下午3点45分moment().calendar();                      // 今天下午3点45分moment().add(1, 'days').calendar();       // 明天下午3点45分moment().add(3, 'days').calendar();       // 本周日下午3点45moment().add(10, 'days').calendar();      // 2015年9月13日

多语言支持

moment().format('L');    // 2015-09-03moment().format('l');    // 2015-09-03moment().format('LL');   // 2015年9月3日moment().format('ll');   // 2015年9月3日moment().format('LLL');  // 2015年9月3日下午3点45分moment().format('lll');  // 2015年9月3日下午3点45分moment().format('LLLL'); // 2015年9月3日星期四下午3点45分moment().format('llll'); // 2015年9月3日星期四下午3点45分

时间段

moment.duration(Number, String);

moment.duration(Number);

moment.duration(Object);

moment.duration(String);

moment.duration(100); // 100 millisecondsmoment.duration(2, 'seconds');moment.duration(2, 'minutes');moment.duration(2, 'hours');moment.duration(2, 'days');moment.duration(2, 'weeks');moment.duration(2, 'months');moment.duration(2, 'years');

更多API:

转载于:https://my.oschina.net/wolfx/blog/637246

你可能感兴趣的文章
使用jquery获取url参数
查看>>
asp.net 获取网站根目录
查看>>
小程序animation动画效果综合应用案例(交流QQ群:604788754)
查看>>
网站头信息的区别所在:
查看>>
web.py实现jsonp
查看>>
20061130: 最近两个礼拜发生的事情;乌班图
查看>>
环信推送 注意点: 会持续更新 :记录接入环信遇到的问题
查看>>
.NET基础——ASSCII码表
查看>>
IE 浏览器的兼容性列表设置
查看>>
CDOJ 26 遮挡判断(shadow) 解题报告
查看>>
imperva 默认策略添加例外
查看>>
[翻译] Autofac 中注册的概念
查看>>
网上购物系统(Task102)——登录控件的使用(登录控件的基本配置)
查看>>
项目添加大量js文件时关闭Eclipse校验机制
查看>>
AC日记——线段树练习4 codevs 4919
查看>>
python之路--初识面向对象
查看>>
云与移动有何共同点?
查看>>
彩票软件3)wpf界面布局
查看>>
【转载】Spring Cloud全家桶主要组件及简要介绍
查看>>
Go解析写死的json
查看>>