zoukankan      html  css  js  c++  java
  • jq 获取除节假日与周六日 外的日期 和 星期

    //设置节假日的数组
            var holiday = Array('2016-04-30','2016-05-01','2016-05-02','2016-06-09','2016-06-10','2016-06-11','2016-09-15','2016-09-16','2016-09-17','2016-10-1','2016-10-01','2016-10-02','2016-10-03','2016-10-04','2016-10-05','2016-10-06','2016-10-07');
     
            // 全局变量
            var fiveDay = Array();//用于保存符合条件的5天的日期
            var fiveWeek = Array();//用于保存符合条件的5天的星期
     
            //生成5个符合条件的日期
            function get_five_day(){
                var index = 0;//用于标记数组已经有的个数
                for(var between=1;index<5;between++){
                    var date = new Date();//Date 对象
                    date.setDate(date.getDate()+between);
                    if(date.getDay()==0 || date.getDay()==6 )continue;
                    var year = date.getFullYear();
                    var month = date.getMonth()+1;
                    month = month<10?'0'+month:month;
                    var day = date.getDate();
                    day = day<10?'0'+day:day;
                    var full_date = year+'-'+month+'-'+day;
                    var flag = true;
                    for(var i = 0;i<holiday.length;i++){//遍历holiday数组
                        if(full_date == holiday[i]) flag = false;
                    }
                    if(flag){
                        fiveDay[index] = full_date; //存进fiveDay数组
                        index++;
                    }
                }
     
            }
     
            //将日期转为星期
            function changWeek(date_str){
                var date = new Date(date_str);  
                var week_day = date.getDay();
                var week_str = '';
     
                switch(week_day){
                    case 1:
                        week_str = '周一';
                        break;
     
                    case 2:
                        week_str = '周二';
                        break;
     
                    case 3:
                        week_str = '周三';
                        break;
     
                    case 4:
                        week_str = '周四';
                        break;
     
                    case 5:
                        week_str = '周五';
                        break;
                }
                return week_str;
            }
     
            // 转5个日期为星期
            function get_five_week_str(){
                for(var i=0;i<5;i++){
                    fiveWeek[i] = changWeek(fiveDay[i]);
                }    
            }
     
            // 执行
            get_five_day();
            get_five_week_str();
            console.log(fiveDay);
  • 相关阅读:
    Linux下通过二进制方式安装mysql5.7版本和系统优化
    SQL中的real、float、decimal、numeric数据类型区别
    SQL中的事务ACID
    一台服务器搭建部署两个或多个Redis实例
    SQLServer数据库镜像高性能模式下维护
    SQLServer配置镜像,无法将 ALTER DATABASE 命令发送到远程服务器实例,数据库镜像配置未更改。请确保该服务器已连接,然后重试。
    阿里云数据库MongoDB版清理oplog日志和compact命令详解
    Linux下shell脚本实现mongodb定时自动备份
    List分组
    Sql Server日期查询-SQL查询今天、昨天、7天内、30天
  • 原文地址:https://www.cnblogs.com/lzs-888/p/5386551.html
Copyright © 2011-2022 走看看