手记

js中的new Date() 系统时间指哪个?怎么修改?

JavaScript的都知道,获取系统当前时间使用的是:

var currentDate = new Date();

new Date() 是哪个时间?

  • new Date() 取到的系统时间和你笔记本的时间有关系么?
    有关系,new Date() 取到的是系统时间,也就是你笔记本上的时间,至于笔记本怎么取时间的,不要问我。

怎么修改笔记本时间?

找到屏幕右下角日期右键,点击调整日期
如下:把自动设置时间关掉,点击下边的更改即可

QQ截图20180424143456.png


验证一下new Date() 是否是我们自己设置的日期

425今天.png


更改到5-5.png


这样就可以在本地进行修改日期进行测试了

            var regDate = /^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/;
            vm.ifEnterDateValid = function(){
                $scope.moreDate = [];                var strDate = $("#datepickerStar").val();                var endDate = $("#datepickerEnd").val();                if(!strDate || !endDate){
                    toaster.error({title: "提示" , body: "起始日期或结束日期不得为空!"} );
                    vm.dateValid = false;
                }else{                    if(!regDate.test(strDate) || !regDate.test(endDate) ){
                        toaster.error({title: "提示" , body: "起始日期或结束日期格式非法,请修改为yyyy-MM-dd,例如:2018-03-16!"} );
                        vm.dateValid = false;
                    }else{                        if(strDate+"" > endDate+""){
                            toaster.error({title: "提示" , body: "起始日期不能大于结束日期!"} );
                            vm.dateValid = false;
                        }else{                            // 最小日期 从填表开始,未超过12点,第二个工作日;否则第三个工作日
                                var currentDate = new Date();                                var currentHour = currentDate.getHours();                                var currentTimeStamp = currentDate.getTime();                                //var isWeek = (minDate.getDay()=='0'||minDate.getDay()=='6')?true:false;
                            // 周五周六周日提交申请 则从下周一开始处理申请,起始日期最小从下周二开始选
                                var isWeek = currentDate.getDay();                                if(isWeek == '0'){
                                    currentTimeStamp+=86400000*2;
                                }else if(isWeek == '6'){
                                    currentTimeStamp+=86400000*3;
                                }else if(isWeek == '5'){                                    if(currentHour >= 12){
                                        currentTimeStamp+=86400000*4;
                                    }else{
                                        currentTimeStamp+=86400000*3;
                                    }
                                }else{                                    if(currentHour >= 12){
                                        currentTimeStamp+=86400000*2;
                                    }else{
                                        currentTimeStamp+=86400000;
                                    }
                                }                                var minDate = new Date(currentTimeStamp);                                var minMonth = minDate.getMonth()+1;

                                minMonth = minMonth>9?minMonth:'0'+minMonth;                                var minDay = minDate.getDate() >9?minDate.getDate():('0'+minDate.getDate());                                var minYMD = minDate.getFullYear()+'-'+minMonth +'-'+minDay;                                if(strDate+"" < minYMD+""){
                                    toaster.error({title: "提示" , body: "自系统提交时间起,若未超过当日12点,起始日期从第二个工作日开始选;若超过当日12点,起始日期从第三个工作日开始选;若周六、周日提交,起始日期则从下周二开始选!"} );
                                    vm.dateValid = false;
                                }else{                                    // 范围不得超过31天
                                    var startTimeStamp = new Date(strDate).getTime();                                    var endTimeStamp = new Date(endDate).getTime();                                    var range = (endTimeStamp - startTimeStamp)/(24*60*60*1000);                                    if(range > 31){
                                        toaster.error({title: "提示" , body: "起始日期与结束日期不得超过31天!"} );
                                        vm.dateValid = false;
                                    }else{                                        var pushDate = strDate+'~'+endDate;                                        //var moreDateStr = $scope.moreDate.join(",");
                                        //if(moreDateStr.indexOf(pushDate) != '-1'){
                                        //    toaster.error({title: "提示" , body: "该时间段已添加,请重新选择时间!"} );
                                        //}else{
                                        //    $scope.moreDate.push(pushDate);
                                        //}
                                        //$("#datepickerStar").val("");
                                        //$("#datepickerEnd").val("");
                                        $scope.moreDate.push(pushDate);
                                    }
                                }
                         }
                    }
                }

            }



作者:_信仰zmh
链接:https://www.jianshu.com/p/c35ee0c9f6d2


1人推荐
随时随地看视频
慕课网APP