function CurentTime()
{
var now = new Date();
var year = now.getFullYear(); //年
var month = now.getMonth() + 1; //月
var day = now.getDate(); //日
var hh = now.getHours(); //时
var mm = now.getMinutes(); //分
var clock = year + "/";
if(month < 10)
clock += "0";
clock += month + "/";
if(day < 10)
clock += "0";
clock += day + " ";
if(hh < 10)
clock += "0";
clock += hh + ":";
if (mm < 10) clock += '0';
clock += mm;
return(clock);
}
function CurentTime2()
{
var now = new Date();
var year = now.getFullYear(); //年
var month = now.getMonth() + 1; //月
var day = now.getDate(); //日
var hh = now.getHours(); //时
var mm = now.getMinutes(); //分
var ss = now.getSeconds();
var clock = year + "/";
if(month < 10)
clock += "0";
clock += month + "/";
if(day < 10)
clock += "0";
clock += day + " ";
if(hh < 10)
clock += "0";
clock += hh + ":";
if (mm < 10) clock += '0';
clock += mm + ":";
if (ss < 10) clock += '0';
clock += ss;
return(clock);
}
function formate_time(str){
var time = new Date(str);
var year = time.getFullYear(); //年
var month = time.getMonth() + 1; //月
var day = time.getDate(); //日
//var hh = time.getHours(); //时
//var mm = time.getMinutes(); //分
var clock = year + "/";
if(month < 10)
clock += "0";
clock += month + "/";
if(day < 10)
clock += "0";
clock += day;
return(clock);
}
function formate_time2(str){
var time = new Date(str);
var year = time.getFullYear(); //年
var month = time.getMonth() + 1; //月
var day = time.getDate(); //日
var hh = time.getHours(); //时
var mm = time.getMinutes(); //分
var ss = time.getSeconds();
var clock = year + "/";
if(month < 10)
clock += "0";
clock += month + "/";
if(day < 10)
clock += "0";
clock += day + " ";
if(hh < 10)
clock += "0";
clock += hh + ":";
if (mm < 10) clock += '0';
clock += mm + ":";
if (ss < 10) clock += '0';
clock += ss;
return(clock);
}
function formate_time3(str){
var time = new Date(str);
var year = time.getFullYear(); //年
var month = time.getMonth() + 1; //月
var day = time.getDate(); //日
var hh = time.getHours(); //时
var mm = time.getMinutes(); //分
// var ss = time.getSeconds();
var clock = year + "/";
if(month < 10)
clock += "0";
clock += month + "/";
if(day < 10)
clock += "0";
clock += day + " ";
if(hh < 10)
clock += "0";
clock += hh + ":";
if (mm < 10) clock += '0';
clock += mm;
//clock += mm + ":";
//if (ss < 10) clock += '0';
//clock += ss;
return(clock);
}
Date.prototype.format = function(format)
{
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 d = new Date();
d.format('yyyy-MM-dd');
https://www.cnblogs.com/mingforyou/category/326335.html