zoukankan      html  css  js  c++  java
  • 使用moment获取当前月份最后一天的23点59分

    获取当前月份最后一天

    //1. 先用moment把时间转化为moment时间
    let time=moment("Mon Jun 06 2020 00:00:00 GMT+0800 (中国标准时间)")
    console.log(time);//Moment {_isAMomentObject: true, _i: "Mon Jun 06 2020 00:00:00 GMT+0800 (中国标准时间)", _isUTC: false, _pf: {…}, _locale: Locale, …}
    //2. 使用endOf('')将当前的原始moment时间对象转化为自定义事件单位的末尾 如果用year就是取传入的时间字符串的当年的最后一天
    let time=moment("Mon Jun 01 2020 00:00:00 GMT+0800 (中国标准时间)").endOf('month')
    console.log(time);
    //Moment {_isAMomentObject: true, _i: "Mon Jun 01 2020 00:00:00 GMT+0800 (中国标准时间)", _isUTC: false, _pf: {…}, _locale: Locale, …}
    //_d: Tue Jun 30 2020 23:59:59 GMT+0800 (中国标准时间) {}
    //_i: "Mon Jun 01 2020 00:00:00 GMT+0800 (中国标准时间)"
    //__proto__: Object
    
    //3. 其中_d就是获取到的值 然后再转成时间戳即可
    let time=moment("Mon Jun 01 2020 00:00:00 GMT+0800 (中国标准时间)").endOf('month').unix()
    console.log(time);//1593532799
    
  • 相关阅读:
    POJ2777
    链表
    模板
    poj 3468(线段树)
    用react编写一个hello world
    用express快速写一个hello world
    naturalWidth与naturalHeight
    div里面的图片垂直居中
    js将网址转为二维码并下载图片
    记一个视频播放器插件 video.js
  • 原文地址:https://www.cnblogs.com/my466879168/p/13256145.html
Copyright © 2011-2022 走看看