資源描述:
《Js獲取當(dāng)前日期時(shí)間及其它操作》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、Js獲取當(dāng)前日期時(shí)間及其它操作varmyDate=newDate();myDate.getYear();????????//獲取當(dāng)前年份(2位)myDate.getFullYear();????//獲取完整的年份(4位,1970-????)myDate.getMonth();???????//獲取當(dāng)前月份(0-11,0代表1月)myDate.getDate();????????//獲取當(dāng)前日(1-31)myDate.getDay();?????????//獲取當(dāng)前星期X(0-6,0代表星期天)myDate.getTime();????????//獲取當(dāng)前時(shí)間(從1970.1.1開(kāi)
2、始的毫秒數(shù))myDate.getHours();???????//獲取當(dāng)前小時(shí)數(shù)(0-23)myDate.getMinutes();?????//獲取當(dāng)前分鐘數(shù)(0-59)myDate.getSeconds();?????//獲取當(dāng)前秒數(shù)(0-59)myDate.getMilliseconds();????//獲取當(dāng)前毫秒數(shù)(0-999)myDate.toLocaleDateString();?????//獲取當(dāng)前日期varmytime=myDate.toLocaleTimeString();?????//獲取當(dāng)前時(shí)間myDate.toLocaleString();???????
3、?//獲取日期與時(shí)間?日期時(shí)間腳本庫(kù)方法列表Date.prototype.isLeapYear判斷閏年Date.prototype.Format日期格式化Date.prototype.DateAdd日期計(jì)算Date.prototype.DateDiff比較日期差Date.prototype.toString日期轉(zhuǎn)字符串Date.prototype.toArray日期分割為數(shù)組Date.prototype.DatePart取日期的部分信息Date.prototype.MaxDayOfDate取日期所在月的最大天數(shù)Date.prototype.WeekNumOfYear判斷日期所在年
4、的第幾周StringToDate字符串轉(zhuǎn)日期型IsValidDate驗(yàn)證日期有效性CheckDateTime完整日期時(shí)間檢查daysBetween日期天數(shù)差js代碼://---------------------------------------------------??//判斷閏年??//---------------------------------------------------??Date.prototype.isLeapYear=function()???{???????return(0==this.getYear()%4&&((this.getYear()%
5、100!=0)
6、
7、(this.getYear()%400==0)));???}?????//---------------------------------------------------??//日期格式化??//格式Y(jié)YYY/yyyy/YY/yy表示年份??//MM/M月份??//W/w星期??//dd/DD/d/D日期??//hh/HH/h/H時(shí)間??//mm/m分鐘??//ss/SS/s/S秒??//---------------------------------------------------??Date.prototype.Format=function(f
8、ormatStr)???{???????varstr=formatStr;???????varWeek=['日','一','二','三','四','五','六'];????????str=str.replace(/yyyy
9、YYYY/,this.getFullYear());???????str=str.replace(/yy
10、YY/,(this.getYear()%100)>9?(this.getYear()%100).toString():'0'+(this.getYear()%100));?????????str=str.replace(/MM/,this.getMonth
11、()>9?this.getMonth().toString():'0'+this.getMonth());???????str=str.replace(/M/g,this.getMonth());?????????str=str.replace(/w
12、W/g,Week[this.getDay()]);?????????str=str.replace(/dd
13、DD/,this.getDate()>9?this.getDate().toString():'0'+this.getDat