zoukankan      html  css  js  c++  java
  • myDataUtil。js


    Date.prototype.Format = function(fmt)
    {
    //author: meizz
    var o =
    {
    "M+" : this.getMonth() + 1, //month
    "d+" : this.getDate(), //day
    "h+" : this.getHours(), //hours
    "m+" : this.getMinutes(), //munutes
    "s+" : this.getSeconds(), //seconds
    "q+" : Math.floor((this.getMonth() + 3) / 3), //floor
    "S" : this.getMilliseconds() //milliseconds
    };
    if (/(y+)/.test(fmt))
    fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt))
    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
    }


    Date.prototype.addDays = function(d)
    {
    this.setDate(this.getDate() + d);
    };


    Date.prototype.addWeeks = function(w)
    {
    this.addDays(w * 7);
    };


    Date.prototype.addMonths= function(m)
    {
    var d = this.getDate();
    this.setMonth(this.getMonth() + m);

    if (this.getDate() < d)
    this.setDate(0);
    };


    Date.prototype.addYears = function(y)
    {
    var m = this.getMonth();
    this.setFullYear(this.getFullYear() + y);

    if (m < this.getMonth())
    {
    this.setDate(0);
    }
    };

    function getUpMonth(){
    var up = new Date();
    up.setMonth(up.getMonth()-1);
    var up_year=up.getFullYear();
    var up_month=up.getMonth()+1;
    var up_day=up.getDate();
    if(up_month<10){
    up_month="0"+up_month;
    }
    if(up_day<10){
    up_day="0"+up_day;
    }
    return up_year+"-"+up_month+"-"+up_day;
    };
    function getThisMonth(){
    var now = new Date();
    var now_year=now.getFullYear();
    var now_month=now.getMonth()+1;
    var now_day=now.getDate();
    if(now_month<10){
    now_month="0"+now_month;
    }
    if(now_day<10){
    now_day="0"+now_day;
    }
    return now_year+"-"+now_month+"-"+now_day;
    };

    -------------------------

    var begin = new Date();
    begin.addMonths(-1);
    var end=new Date();

    if($("input[name=beginDate]").val()==""){
    $("input[id='beginDate']").val(begin.Format("yyyy-MM-dd"));
    }
    if($("input[name=endDate]").val()==""){
    $("input[name=endDate]").val(end.Format("yyyy-MM-dd"));
    }

  • 相关阅读:
    《必须知道的.net》读后感 转
    Web Service
    设计模式
    对做“互联网产品”的一些想法
    四大发明之活字印刷——面向对象思想的胜利
    每个IT人都应当拥有的30条技能
    面向对象的本质是什么?
    数据库设计规范 zhuan
    翻动100万级的数据 —— 只需几十毫秒 转
    程序员发展十分重要的12条日常习惯
  • 原文地址:https://www.cnblogs.com/yangy608/p/2428837.html
Copyright © 2011-2022 走看看