• moment.js(时间格式化js)


    文档地址    http://momentjs.cn/

    安装

    1 npm install moment --save # npm 
    2 yarn add moment # Yarn 
    3 Install-Package Moment.js # NuGet 
    4 spm install moment --save # spm 
    5 meteor add momentjs:moment # meteor

    日期格式化

    moment().format('MMMM Do YYYY, h:mm:ss a'); // 十一月 2日 2020, 4:35:28 下午
    moment().format('dddd');                    // 星期一
    moment().format("MMM Do YY");               // 11月 2日 20
    moment().format('YYYY [escaped] YYYY');     // 2020 escaped 2020
    moment().format();                          // 2020-11-02T16:35:28+08:00

    相对时间

    moment("20111031", "YYYYMMDD").fromNow(); // 9 年前
    moment("20120620", "YYYYMMDD").fromNow(); // 8 年前
    moment().startOf('day').fromNow();        // 17 小时前
    moment().endOf('day').fromNow();          // 7 小时内
    moment().startOf('hour').fromNow();       // 35 分钟前

    日历时间

    moment().subtract(10, 'days').calendar(); // 2020/10/23
    moment().subtract(6, 'days').calendar();  // 上星期二16:35
    moment().subtract(3, 'days').calendar();  // 上星期五16:35
    moment().subtract(1, 'days').calendar();  // 昨天16:35
    moment().calendar();                      // 今天16:35
    moment().add(1, 'days').calendar();       // 明天16:35
    moment().add(3, 'days').calendar();       // 下星期四16:35
    moment().add(10, 'days').calendar();      // 2020/11/12

    多语言支持

    moment.locale();         // zh-cn
    moment().format('LT');   // 16:35
    moment().format('LTS');  // 16:35:28
    moment().format('L');    // 2020/11/02
    moment().format('l');    // 2020/11/2
    moment().format('LL');   // 2020年11月2日
    moment().format('ll');   // 2020年11月2日
    moment().format('LLL');  // 2020年11月2日下午4点35分
    moment().format('lll');  // 2020年11月2日 16:35
    moment().format('LLLL'); // 2020年11月2日星期一下午4点35分
    moment().format('llll'); // 2020年11月2日星期一 16:35

      

  • 相关阅读:
    C++ Primer 第五版-1.1
    C++ Primer 第五版笔记-1.0
    TouchID
    正则表达式
    duplicate symbol 错误
    第三方登录
    AFNetWorking
    IOS---通知
    左右点击--日期增减
    Xcode相关设置
  • 原文地址:https://www.cnblogs.com/ly1368489670/p/13915185.html
Copyright © 2020-2023  润新知