js获取当前时间 格式“yyyy-MM-dd HH:MM:SS”
js获取当前时间 格式“yyyy-MM-dd HH:MM:SS”
function getNowFormatDate() {
var date = new Date(); //获取当前时间
var month = date.getMonth() + 1; //月份处理
var day= date.getDate();
month= (month< 10) ? ('0' + month): month;//月份为1-9月,在其前面加0
day=(day< 10)?("0" + day):day;//日期为1-9号,在其前面加了0
var s1 = "-";//定义年月日分隔符-
var s2 = ":";//定义时分秒分隔符:
//拼接年月日,时分秒
var currDate = date.getFullYear() + s1 + month + s1 + day
+ " " + date.getHours() + s2 + date.getMinutes()+ s2 + date.getSeconds();
return currDate;
}