色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

Javascript 日期對象Date擴展方法

今天在網(wǎng)上摘抄了些js中操作日期的相關(guān)方法,現(xiàn)在與大家分享一下。
復(fù)制代碼 代碼如下:
<script type="text/Javascript">
Date.prototype.Format = function(fmt)
{
//author: meizz
var o =
{
"M+" : this.getMonth() + 1, //月份
"d+" : this.getDate(), //日
"h+" : this.getHours(), //小時
"m+" : this.getMinutes(), //分
"s+" : this.getSeconds(), //秒
"q+" : Math.floor((this.getMonth() + 3) / 3), //季度
"S" : this.getMilliseconds() //毫秒
};
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);
}
};
//測試 var now = new Date(); now.addDays(1);//加減日期操作 alert(now.Format("yyyy-MM-dd"));
Date.prototype.dateDiff = function(interval,endTime)
{
switch (interval)
{
case "s": // 主站蜘蛛池模板: 吴旗县| 刚察县| 澎湖县| 土默特右旗| 盐亭县| 都兰县| 蕉岭县| 夏河县| 合江县| 南安市| 延庆县| 新丰县| 秀山| 涞水县| 临清市| 富平县| 丰镇市| 宜城市| 泽普县| 海伦市| 肇州县| 新田县| 织金县| 长兴县| 新河县| 盐池县| 广宁县| 大冶市| 漯河市| 崇文区| 沈丘县| 宁波市| 丽江市| 怀来县| 来凤县| 新野县| 稻城县| 辽宁省| 白城市| 邵阳市| 蒙阴县|