zoukankan      html  css  js  c++  java
  • 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;
    注:这个是从周一开始算一周的开始,周日为结束。
  • 相关阅读:
    加载声音的过程
    onkeyup,onkeydown和onkeypress
    加载着色器的异常

    3
    1
    1
    java总结
    环路
    own address as source address
  • 原文地址:https://www.cnblogs.com/blogs-8888/p/9585293.html
Copyright © 2011-2022 走看看