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;
    注:这个是从周一开始算一周的开始,周日为结束。
  • 相关阅读:
    https进行配置以及http跳转到https配置
    centos7修改系统语言为简体中文
    iptables snat 和dnat说明
    python多线程执行类中的静态方法
    python 磁盘空间操作
    python logging 工具
    python 动态调用函数
    python 读写XML
    js加载json数据成表格
    python 比较两个数据库postgresql
  • 原文地址:https://www.cnblogs.com/blogs-8888/p/9585293.html
Copyright © 2011-2022 走看看