JS 获取当前日期(yy-mm-dd HH-MM-SS)
Posted akon
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JS 获取当前日期(yy-mm-dd HH-MM-SS)相关的知识,希望对你有一定的参考价值。
function getNowDate() {
var date = new Date();
var seperator1 = "-";
var seperator2 = ":";
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var Hours = date.getHours();
var Minutes = date.getMinutes();
var Seconds = date.getSeconds();
if (Hours >= 0 && Hours <= 9) {
Hours = "0" + Hours;
}
if (Minutes >= 0 && Minutes <= 9) {
Minutes = "0" + Minutes;
}
if (Seconds >= 0 && Seconds <= 9) {
Seconds = "0" + Seconds;
}
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
+ " " + Hours + seperator2 + Minutes
+ seperator2 + Seconds;
return currentdate;
}
以上是关于JS 获取当前日期(yy-mm-dd HH-MM-SS)的主要内容,如果未能解决你的问题,请参考以下文章