一起学习网 一起学习网


js格式化时间和js格式化时间戳示例

网络编程 js格式化时间和js格式化时间戳示例 06-21


/**
* 时间对象的格式化;
*/
Date.prototype.format = function(format) {
/*
* eg:format="YYYY-MM-dd hh:mm:ss";
*/
var o = {
"M+" :this.getMonth() + 1, // month
"d+" :this.getDate(), // day
"h+" :this.getHours(), // hour
"m+" :this.getMinutes(), // minute
"s+" :this.getSeconds(), // second
"q+" :Math.floor((this.getMonth() + 3) / 3), // quarter
"S" :this.getMilliseconds()
// millisecond
}

if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear() + "")
.substr(4 - RegExp.$1.length));
}

for ( var k in o) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
: ("00" + o[k]).substr(("" + o[k]).length));
}
}
return format;
}


var now = new Date().format("yyyy-MM-dd hh:mm:ss");


new Date().format("yy-MM-dd hh:mm");

JavaScript类属性的访问方式详解
JavaScript类属性的访问方式varfish={head:1,tail:1,feature:{speak:false,swim:true}}其一,点操作符:console.log(fish.head);//1console.log(fish.tail);//1console.log(fish.feature);//Object{

javascript函数重载解决方案分享
JS的函数定义可以指定形式参数名称,多多少少我们会以为js至少可以支持参数个数不同的方法重载,然而遗憾的是这仅仅是一个假象,js所有的参数都

javascript异步编程的4种方法
你可能知道,Javascript语言的执行环境是"单线程"(singlethread)。所谓"单线程",就是指一次只能完成一件任务。如果有多个任务,就必须排队,前面一


编辑:一起学习网

标签:参数,单线程,函数,的是,方式