zoukankan      html  css  js  c++  java
  • 对Moment.js的研究

    创建
    npm install moment --save-dev

    日期格式化

    moment().format('MMMM Do YYYY, h:mm:ss a'); // 六月 4日 2019, 6:24:10 晚上
    moment().format('dddd');                    // 星期二
    moment().format("MMM Do YY");               // 6月 4日 19
    moment().format('YYYY [escaped] YYYY');     // 2019 escaped 2019
    moment().format();                          // 2019-06-04T18:24:10+08:00

    相对时间

    moment("20111031", "YYYYMMDD").fromNow(); // 8 年前

    moment("20120620", "YYYYMMDD").fromNow(); //7 年前

    moment().startOf('day').fromNow(); // 18 小时前

    moment().endOf('day').fromNow(); // 6 小时内

    moment().startOf('hour').fromNow(); // 30 分钟前

    日历时间

    moment().subtract(10, 'days').calendar(); // 2019年5月25日

    moment().subtract(6, 'days').calendar(); // 上周三晚上6点32

    moment().subtract(3, 'days').calendar(); // 上周六晚上6点32

    moment().subtract(1, 'days').calendar(); // 昨天晚上6点32分

    moment().calendar(); // 今天晚上6点32分

    moment().add(1, 'days').calendar(); // 明天晚上6点32分

    moment().add(3, 'days').calendar(); // 本周五晚上6点32

    moment().add(10, 'days').calendar(); // 2019年6月14日

    多语言支持

    moment().format('L');    // 2019-06-04
    moment().format('l');    // 2019-06-04
    moment().format('LL');   // 2019年6月4日
    moment().format('ll');   // 2019年6月4日
    moment().format('LLL');  // 2019年6月4日晚上6点33分
    moment().format('lll');  // 2019年6月4日晚上6点33分
    moment().format('LLLL'); // 2019年6月4日星期二晚上6点33分
    moment().format('llll'); // 2019年6月4日星期二晚上6点33分

































































     















































  • 相关阅读:
    linux系统中对SSD硬盘优化的方法
    正则
    自己写的博客上线啦
    create-react-app部署到GitHub Pages时报错:Failed to get remote。origin.url
    使用react-redux开发的简单步骤
    使用redux开发的简单步骤
    使用combineReducers注意事项
    在前端页面展示Markdown文件
    React Router V4.0学习笔记
    为什么React事件处理函数必须使用Function.bind()绑定this?
  • 原文地址:https://www.cnblogs.com/zhouyideboke/p/10975369.html
Copyright © 2011-2022 走看看