zoukankan      html  css  js  c++  java
  • 点击获取今天时间、明天时间、本周时间、本月时间

    function DateTime(Tid) {
        var now = new Date();
        var validDate = "",
            day = now.getDate(),
            month = now.getMonth(),
            year = now.getFullYear();
        var nowTime = now.getTime();
        var oneDayTime = 24 * 60 * 60 * 1000;
        var mDay = now.getDay(); /*显示周一*/
        var MondayTime = nowTime - (mDay - 1) * oneDayTime; /*显示周日*/
        var SundayTime = nowTime + (7 - mDay) * oneDayTime; /*初始化日期时间*/
        var monday = new Date(MondayTime);
        var sunday = new Date(SundayTime);
        switch (Tid) {
            case "1":
                validDate = year + '.' + (month + 1) + '.' + day;
                break;
            case "2":
                validDate = year + '.' + (month + 1) + '.' + (day + 1);
                break;
            case "3":
                validDate = monday.getFullYear() + '.' + (monday.getMonth() + 1) + '.' + monday.getDate() + '~' + sunday.getFullYear() + '.' + (sunday.getMonth() + 1) + '.' + sunday.getDate();
                break;
            case "4":
                var tempdate = year + '.' + (month + 1),
                    enddate = getCurrentMonthLast(new Date(tempdate));
                validDate = year + '.' + (month + 1) + '.1~' + tempdate + '.' + enddate;
                break;
        }
        if (validDate) {
            validDate = '有效期限:' + validDate;
            $('.js-validdate').text(validDate);
        }
    
        function getCurrentMonthLast(date) {
            var currentMonth = date.getMonth();
            var nextMonth = ++currentMonth;
            var nextMonthFirstDay = new Date(date.getFullYear(), nextMonth, 1);
            var oneDay = 1000 * 60 * 60 * 24;
            return new Date(nextMonthFirstDay - oneDay).getDate();
        }
    }

    Tid是点击今天时间、明天时间、本周时间、本月时间的id

  • 相关阅读:
    _1_html_框架
    _0_web_基础
    _0_工具
    虚拟机安装与使用
    NumPy数据类型
    NumPy Ndarray对象
    机器学习之K-近邻(KNN)算法
    vue项目如何打包扔向服务器
    Eslint 规则说明
    Python ssh 远程执行shell命令
  • 原文地址:https://www.cnblogs.com/520yh/p/13728319.html
Copyright © 2011-2022 走看看