欢迎来到258分享网,纯净的网络源码分享基地!

258资源分享网

全部作品
全部作品
网站源码
微信源码
素材特效
源码插件
视频教程
建站学院
热门搜索: 织梦  农业种植  农业  安全设置  官方
258资源分享 > 建站学院 > 微信开发 > 扩展微信小程序框架功能:日期时间Moment.js

推荐下载

HTML5响应式自适应网咯设计

2020-05-12   浏览:736

高端HTML5响应式企业通用网

2020-05-06   浏览:518

html5响应式外贸网站英文版

2020-05-08   浏览:505

HTML5自适应律师工作室类网

2020-04-04   浏览:501

HTML5影视传媒文化公司类网

2020-05-12   浏览:495

扩展微信小程序框架功能:日期时间Moment.js

发布时间:2020-12-06  

Moment.js是一个JavaScript的日期、时间处理工具类,其对于JavaScript的日期时间处理功能非常强悍和全面。可以用在浏览器环境中使用,也可以在Node.js中。

Moment.js

Moment.js对Date对象的扩展不是使用Date.prototype的方式,是对Date对象创建一个包装对象。通过moment()方法可以获取这个包装对象,并且可以在调用时传入一个支持的输入参数。

Moment.js 使用

获取当前日期时间,使用moment()方法即可,无需传入任何参数:

   var now = moment();

日期格式化

   console.log(moment().format('MMMM Do YYYY, h:mm:ss a')); // 输出:January 3rd 2017, 2:16:38 pm    console.log(moment().format('dddd')); // 输出:Tuesday    console.log(moment().format("MMM Do YY")); // 输出:Jan 3rd 17    console.log(moment().format('YYYY [escaped] YYYY')); // 输出:2017 escaped 2017    console.log(moment().format()); // 输出:2017-01-03T14:20:03+08:00    console.log();

相对时间

   console.log(moment("20111031", "YYYYMMDD").fromNow()); // 输出:5 years ago    console.log(moment("20120620", "YYYYMMDD").fromNow()); // 输出:5 years ago    console.log(moment().startOf('day').fromNow()); // 输出:14 hours ago    console.log(moment().endOf('day').fromNow()); // 输出:in 10 hours    console.log(moment().startOf('hour').fromNow()); // 输出:22 minutes ago    console.log();

日历时间

   console.log(moment().subtract(10, 'days').calendar()); // 输出:12/24/2016    console.log(moment().subtract(6, 'days').calendar()); // 输出:Last Wednesday at 2:24 PM    console.log(moment().subtract(3, 'days').calendar()); // 输出:Last Saturday at 2:24 PM    console.log(moment().subtract(1, 'days').calendar()); // 输出:Yesterday at 2:24 PM    console.log(moment().calendar()); // 输出:Today at 2:24 PM    console.log(moment().add(1, 'days').calendar()); // 输出:Tomorrow at 2:24 PM    console.log(moment().add(3, 'days').calendar()); // 输出:Friday at 2:24 PM    console.log(moment().add(10, 'days').calendar()); // 输出:01/13/2017    console.log();

多语言支持

   console.log(moment.locale()); // 输出:en    var m = moment().locale('zh-cn');          console.log(m.format('LT')); // 输出:下午2点33分    console.log(m.format('LTS')); // 输出:下午2点33分52秒    console.log(m.format('L')); // 输出:2017-01-03    console.log(m.format('l')); // 输出:2017-01-03    console.log(m.format('LL')); // 输出:2017年1月3日    console.log(m.format('ll')); // 输出:2017年1月3日    console.log(m.format('LLL')); // 输出:2017年1月3日下午2点33分    console.log(m.format('lll')); // 输出:2017年1月3日下午2点33分    console.log(m.format('LLLL')); // 输出:2017年1月3日星期二下午2点33分    console.log(m.format('llll')); // 输出:2017年1月3日星期二下午2点33分 参考资料

Moment.js

Moment.js@github

Moment.js中文网

Moment.js中文文档系列

其他

完整代码:https://github.com/guyoung/GyWxappCases/tree/master/Enhance

微信小程序Canvas增强组件WeZRender:https://github.com/guyoung/WeZRender