现在的位置: 首页 > 综合 > 正文

js控制格式化时间(30天,一周,最近3天)

2013年10月09日 ⁄ 综合 ⁄ 共 1729字 ⁄ 字号 评论关闭

//格式化时间
    Date.prototype.format = function(format){
        var o = {
        "M+" : this.getMonth()+1, //month
        "d+" : this.getDate(),    //day
        "h+" : this.getHours(),   //hour
        "m+" : this.getMinutes(), //minute
        "s+" : this.getSeconds(), //second
        "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
        "S" : this.getMilliseconds() //millisecond
        }
        if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
        (this.getFullYear()+"").substr(4 - RegExp.$1.length));
        for(var k in o)if(new RegExp("("+ k +")").test(format))
        format = format.replace(RegExp.$1,
        RegExp.$1.length==1 ? o[k] :
        ("00"+ o[k]).substr((""+ o[k]).length));
        return format;
    }

    function changeDate(days){
       var today=new Date(); // 获取今天时间
       var begin;
       var endTime;
      if(days == 3){
          today.setTime(today.getTime()-3*24*3600*1000);
          begin = today.format('yyyy-MM-dd');
          end =new Date().format('yyyy-MM-dd');
      }else if(days == 7){
          today.setTime(today.getTime()-7*24*3600*1000);
          begin = today.format('yyyy-MM-dd');
          end =new Date().format('yyyy-MM-dd');
      }else if(days == 30){
            today.setTime(today.getTime()-30*24*3600*1000);
          begin = today.format('yyyy-MM-dd');
          end =new Date().format('yyyy-MM-dd');
      }
      var status =$("#status").val();
      $("#begintime").val(begin);
      $("#endtime").val(end);
      document.location.href = "/managerShop/searchxsorder.action?method=xsother"
                + "&begintime=" + begin + "&endtime=" + end
                + "&status="+status+ "&orderId=";
    }




[<a href="javascript:changeDate(3)">最新3天</a><a href="javascript:changeDate(7)">最近一周</a><a href="javascript:changeDate(30)" style="margin-right:2px;">最近30天</a>]

抱歉!评论已关闭.