标签:
1.拼凑
var myDate = new Date();
var weekday=new Array(7)
weekday[0]="星期日"
weekday[1]="星期一"
weekday[2]="星期二"
weekday[3]="星期三"
weekday[4]="星期四"
weekday[5]="星期五"
weekday[6]="星期六"
var currDate = myDate.getYear()+1900+"年"+myDate.getMonth()+1+"月"+myDate.getDate()+"日 "+weekday[myDate.getDay()];
document.getElementById("currDate").innerHTML = currDate;
效果:2016年01月13日 星期三
2.自定义
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;
}
var currDate = new Date().Format("yyyy-MM-dd hh:mm:ss");
document.getElementById("currDate").innerHTML = currDate;
效果:2016-01-13 14:58:51
currDate
标签:
原文地址:http://www.cnblogs.com/luoxiaolei/p/5127336.html