样式:
代码:
//获取当前时间戳
var myDate = new Date();
var year = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
var month = Number(myDate.getMonth() + 1) + ""; //获取当前月份(0-11,0代表1月)
var date = myDate.getDate() + ""; //获取当前日(1-31)
//获取当前时
var hour = myDate.getHours() < 10 ? "0" + myDate.getHours() : myDate.getHours();
//获取当前分
var minute = myDate.getMinutes() < 10 ? "0" + myDate.getMinutes() : myDate.getMinutes();
//获取当前秒
var second = myDate.getSeconds() < 10 ? "0" + myDate.getSeconds() : myDate.getSeconds();
//获取星期
var week = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六")[myDate.getDay()];
if (date.length == 1) {
date = "0" + date
}
if (month.length == 1) {
month = "0" + month
}
//当前日期
var now_time = year + '-' + month + '-' + date + ' ' + hour + ':' + minute + ':' + second + ' ' + week
console.log("当前时间:" + now_time)
全部评论