• js获取一周的日期范围


    function getWeek() {
    				this.nowTime = new Date();
    				this.init = function() {
    					this.dayInWeek = this.nowTime.getDay();
    					this.dayInWeek == 0 && (this.dayInWeek = 7);
    					this.thsiWeekFirstDay = this.nowTime.getTime() - (this.dayInWeek - 1) * 86400000;
    					this.thisWeekLastDay = this.nowTime.getTime() + (7 - this.dayInWeek) * 86400000;
    					return this;
    				};
    				this.getWeekType = function(type) {
    					type = ~~type;
    					var firstDay = this.thsiWeekFirstDay + type * 7 * 86400000;
    					var lastDay = this.thisWeekLastDay + type * 7 * 86400000;
    					return this.getWeekHtml(firstDay, lastDay);
    				}
    				this.formateDate = function(time) {
    					var newTime = new Date(time)
    					var year = newTime.getFullYear();
    					var month = newTime.getMonth() + 1;
    					var day = newTime.getDate();
    					return year + "-" + (month >= 10 ? month : "0" + month) + "-" + (day >= 10 ? day : "0" + day);
    				};
    				this.getWeekHtml = function(f, l) {
    					return this.formateDate(f) + "至" + this.formateDate(l);
    				};
    			}
    			var getWeek = new getWeek();
    			var week = getWeek.init().getWeekType();
    			console.log(week);
    

      

    getWeekType()这个方法如果不传参数 或者传入0,返回的是本周的日期范围,如果要下周的范围则传入1,上周的传入-1;
    注:这个是从周一开始算一周的开始,周日为结束。
  • 相关阅读:
    接口测试
    Appium应用
    adb常用指令与APPium环境搭建
    移动端专项测试
    tomcat修改端口号
    Linux之Redis安装
    FTL常用标签及语法
    .ftl文件介绍
    maven之clean、install命令
    tomcat环境变量详细配置步骤
  • 原文地址:https://www.cnblogs.com/blogs-8888/p/9585293.html
Copyright © 2020-2023  润新知