Javascript獲取時(shí)間函數(shù),具體代碼如下:
//獲取時(shí)間
function curDateTime() {
var d = new Date();
var year = d.getFullYear() + "";
var month = d.getMonth() + 1;
var date = d.getDate();
var day = d.getDay();
var Hours = d.getHours(); //獲取當(dāng)前小時(shí)數(shù)(0-23)
var Minutes = d.getMinutes(); //獲取當(dāng)前分鐘數(shù)(0-59)
var Seconds = d.getSeconds(); //獲取當(dāng)前秒數(shù)(0-59)
var curDateTime = year;
if (month > 9) {
curDateTime = curDateTime + month;
}
else {
curDateTime = curDateTime + "0" + month;
}
if (date > 9)
curDateTime = curDateTime + date;
else
curDateTime = curDateTime + "0" + date;
if (Hours > 9)
curDateTime = curDateTime + Hours;
else
curDateTime = curDateTime + "0" + Hours;
if (Minutes > 9)
curDateTime = curDateTime + Minutes;
else
curDateTime = curDateTime + "0" + Minutes;
if (Seconds > 9)
curDateTime = curDateTime + Seconds;
else
curDateTime = curDateTime + "0" + Seconds;
//alert(curDateTime);
return curDateTime;
}
更多信息請(qǐng)查看IT技術(shù)專(zhuān)欄