日期:2014-05-17  浏览次数:20699 次

多年积累的js日期代码倾情奉献
JScript code



<script language=Javascript>
String.prototype.Left = function(len){

        if(isNaN(len)||len==null){

                len = 0;

        } else {

         if(parseInt(len)<0||parseInt(len)>this.length) {

                        len = 0;

                }

        }

        return this.substr(0,this.length-len)+'**';

}

//日期自动补零程序

function appendZero(n)

{

        return(("00"+ n).substr(("00"+ n).length-2));

}

//获得当年当月最大天数

function GetMonthMaxDay(theYear,theMonth){  

  var theDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

  var theMonthDay = 0, tmpYear = this.formatYear(theYear);

  theMonthDay = theDays[theMonth];

  if (theMonth == 1){ //theMonth is February

          if (((tmpYear % 4 == 0) && (tmpYear % 100 != 0)) || (tmpYear % 400 == 0)){

                  theMonthDay++;

          }

  }

  return(theMonthDay);

}

//把年份格式化成4位

function formatYear(theYear){  

  var tmpYear = parseInt(theYear,10);

  if (tmpYear < 100){

  tmpYear += 1900;

  if (tmpYear < 1940){

  tmpYear += 100;

  }

  }

  if (tmpYear < this.MinYear){

  tmpYear = this.MinYear;

  }

  if (tmpYear > this.MaxYear){

  tmpYear = this.MaxYear;

  }

  return(tmpYear);

}





------解决方案--------------------
感谢分享
------解决方案--------------------
这次LZ没贴博客地址啊 LZ别的贴子都有贴的啊
------解决方案--------------------
虽说有日期控件 可是这代码是可以用来提高的
------解决方案--------------------
thanks for your work.