zoukankan      html  css  js  c++  java
  • 根据 yyyymmdd格式日期取得当前日期所在周的开始和结束日期

    Js 根据所选日期获取当天是周几,并获取本周的开始日期和结束日期

    在这里设置的一周的开始日期为周一,结束未周末

    //检查本周是否已经填报

    function checkHasAdd(){

             var createDate = jQuery("#createDateId").val();                   

             var weekStartDate = getStarOrEndDay(createDate,0)

             var weekEndDate = getStarOrEndDay(createDate,1)

             jQuery.ajax({

                type: "get",

                url: "ajax.asp",

                data: "weekStartDate="+weekStartDate+"&weekEndDate="+weekEndDate+"&pId="+<%=pid%>,

                cache:false,

                success: function(msg){

                                if(msg == 1) {

                                         alert("本周资金余额周报已经提交!");

                                         jQuery(window.parent.document).find("#btnSaveId").attr("disabled","true");

                                         jQuery(window.parent.document).find("#btnFlow0Id").attr("disabled","true");

                                }

                                else {

                                         jQuery(window.parent.document).find("#btnSaveId").removeAttr("disabled");

                                         jQuery(window.parent.document).find("#btnFlow0Id").removeAttr("disabled");

                       }

                }

             });

    }

    //获取所选日期所在周的开始日期和结束日期 0:本周开始日期,其他:本周结束日期

    function getStarOrEndDay(createDate,types){

             var createDate = jQuery("#createDateId").val();  

             createDate = getDate(createDate);

             var currentDay=createDate.getDay();//获取当前时间是周几使用该方法获取的周是0-6,如果是0,把0转换为7

             if(currentDay==0){

                       currentDay=7

             }

             if (types==0){

                       var mondayTime=createDate.getTime()-(currentDay-1)*24*60*60*1000;//日期转换为毫秒

                       var starDay = new Date(mondayTime);

                       starDay.setTime(starDay);   //把毫秒在转换为日期格式

                       return formatDate(starDay) //格式化为 yyyy-mm-dd格式的时间

             }

             else{

                       var sundayTime=createDate.getTime()+(7-currentDay)*24*60*60*1000;

                       var endDay = new Date(sundayTime)

                       return formatDate(endDay);

             }

    }

    //格式化日期为yyyy-mm-dd格式

    function formatDate(date) {     

             var myyear = date.getFullYear();    

        var mymonth = date.getMonth()+1;    

        var myweekday = date.getDate();     

        if(mymonth < 10){    

            mymonth = "0" + mymonth;    

        }     

        if(myweekday < 10){    

            myweekday = "0" + myweekday;    

        }    

        return (myyear+"-"+mymonth + "-" + myweekday);     

    }

     //字符串转日期格式,strDate要转为日期格式的字符串

    //子页面获取的strDate为字符串类型,把字符串的日期转换为标准的日期时间

    function getDate(strDate) {

             var date = eval('new Date(' + strDate.replace(/\d+(?=-[^-]+$)/,

             function (a) { return parseInt(a, 10) - 1; }).match(/\d+/g) + ')');

             return date;

    }

  • 相关阅读:
    图论
    后缀数组专题
    AC自动机
    线段树·二
    nginx实现负载均衡
    关于mysql binlog二进制
    linux下每次git clone无需多次输入账号密码
    Centos7 yum安装 MySQL5.7.25
    docker基本操作和部署
    composer update 或者 composer install提示killed解决办法
  • 原文地址:https://www.cnblogs.com/zhuifengnianshao/p/3074270.html
Copyright © 2011-2022 走看看