资源描述:
《Js获取当前日期时间及其它操作》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Js获取当前日期时间及其它操作varmyDate=newDate();myDate.getYear(); //获取当前年份(2位)myDate.getFullYear(); //获取完整的年份(4位,1970-????)myDate.getMonth(); //获取当前月份(0-11,0代表1月)myDate.getDate(); //获取当前日(1-31)myDate.getDay(); //获取当前星期X(0-6,0代表星期天)myDate.getTime(); //获取当前时间(从1970.1.1开
2、始的毫秒数)myDate.getHours(); //获取当前小时数(0-23)myDate.getMinutes(); //获取当前分钟数(0-59)myDate.getSeconds(); //获取当前秒数(0-59)myDate.getMilliseconds(); //获取当前毫秒数(0-999)myDate.toLocaleDateString(); //获取当前日期varmytime=myDate.toLocaleTimeString(); //获取当前时间myDate.toLocaleString();
3、 //获取日期与时间 日期时间脚本库方法列表Date.prototype.isLeapYear判断闰年Date.prototype.Format日期格式化Date.prototype.DateAdd日期计算Date.prototype.DateDiff比较日期差Date.prototype.toString日期转字符串Date.prototype.toArray日期分割为数组Date.prototype.DatePart取日期的部分信息Date.prototype.MaxDayOfDate取日期所在月的最大天数Date.prototype.WeekNumOfYear判断日期所在年
4、的第几周StringToDate字符串转日期型IsValidDate验证日期有效性CheckDateTime完整日期时间检查daysBetween日期天数差js代码://--------------------------------------------------- //判断闰年 //--------------------------------------------------- Date.prototype.isLeapYear=function() { return(0==this.getYear()%4&&((this.getYear()%
5、100!=0)
6、
7、(this.getYear()%400==0))); } //--------------------------------------------------- //日期格式化 //格式YYYY/yyyy/YY/yy表示年份 //MM/M月份 //W/w星期 //dd/DD/d/D日期 //hh/HH/h/H时间 //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