zoukankan      html  css  js  c++  java
  • js 获取本月月初和月末时间操作

    方案三,同方案一,只是加入了日期转时间戳操作:

    getCurrentMonth(){
                    let firstDate = new Date();
                    let startDate = firstDate.getFullYear()+"-"+((firstDate.getMonth()+1)<10?"0":"")+(firstDate.getMonth()+1)+"-"+"01";
                    //alert(firstDate.getFullYear()+"-"+((firstDate.getMonth()+1)<10?"0":"")+(firstDate.getMonth()+1)+"-"+"01");
    
                    let date=new Date();
                    let currentMonth=date.getMonth();
                    let nextMonth=++currentMonth;
                    let nextMonthFirstDay=new Date(date.getFullYear(),nextMonth,1);
                    let oneDay=1000*60*60*24;
                    let lastDate =  new Date(nextMonthFirstDay-oneDay);
                    let  endDate = lastDate.getFullYear()+"-"+((lastDate.getMonth()+1)<10?"0":"")+(lastDate.getMonth()+1)+"-"+(lastDate.getDate()<10?"0":"")+lastDate.getDate();
    
                    //console.log('开始时间',startDate)
                    this.start_time = Date.parse(startDate)
                    console.log('开始时间====时间戳',Date.parse(startDate))
                    this.end_time = Date.parse(endDate)
                    //console.log('结束时间', endDate)
                    console.log('结束时间====时间戳', Date.parse(endDate))
                    //alert(lastDate.getFullYear()+"-"+((lastDate.getMonth()+1)<10?"0":"")+(lastDate.getMonth()+1)+"-"+(lastDate.getDate()<10?"0":"")+lastDate.getDate());
                },

    方案二:

    无论是上一个月还是下一个,或者是指定月份稍加改动编可以

    以下例子为计算下个月第一天和最后一天

    setDate(){
        let curDate = new Date();
        let y = curDate.getFullYear();
        let m = curDate.getMonth() + 2;//本身就得+1才等于当前月份,然而我要计算下一个月,所以直接+2
        if( m > 12 ){
            m = 1;
            y++ 
         }
        let monthLastDay = new Date(y,m,0).getDate();
        this.formxg.syqxks = y + '-' + (m < 10 ? '0'+m : m) + '-' + '01';
        this.formxg.syqxjs = y + '-' + (m < 10 ? '0'+m : m) + '-' + (monthLastDay < 10 ? '0'+monthLastDay : monthLastDay);
     },
     
    如非软弱,怎会连触手可及的幸福也要放弃?--纵力量绵薄,也要筑起通往梦想的桥梁!


    据说星星比较有用:https://github.com/zxyuns/bluemoon
  • 相关阅读:
    python集成开发环境Anaconda的安装
    hasMap2
    WireShark:TCP三次握手 抓包
    CCF 201409-4 最优配餐
    201403-4 无线网络
    java IO的字节流和字符流及其区别
    平衡二叉树DSW算法
    警惕Java编译器中那些“蜜糖”陷阱
    laravel 学习笔记 —— 神奇的服务容器
    LNMP下安装phpmyadmin的一个小错误解决办法
  • 原文地址:https://www.cnblogs.com/zxyun/p/14812351.html
Copyright © 2011-2022 走看看