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

Javascript 日期對象Date擴展方法

今天在網上摘抄了些js中操作日期的相關方法,現在與大家分享一下。
復制代碼 代碼如下:
<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": // 主站蜘蛛池模板: 阿城市| 虹口区| 抚远县| 邛崃市| 新和县| 红安县| 景德镇市| 华宁县| 广宗县| 云梦县| 井冈山市| 堆龙德庆县| 盘山县| 固原市| 凯里市| 东台市| 济源市| 时尚| 资溪县| 罗平县| 恭城| 崇仁县| 武宣县| 绍兴县| 四川省| 新蔡县| 桃源县| 贵港市| 华蓥市| 宜宾市| 凌云县| 淮滨县| 桐梓县| 玛曲县| 纳雍县| 玛沁县| 鄂托克旗| 马关县| 高淳县| 太仓市| 舒城县|