码迷,mamicode.com
首页 > Web开发 > 详细

JS 获取当前日期(yy-mm-dd HH-MM-SS)

时间:2017-07-14 16:19:34      阅读:272      评论:0      收藏:0      [点我收藏+]

标签:日期   date   date()   获取   min   mon   current   get   tno   

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)

标签:日期   date   date()   获取   min   mon   current   get   tno   

原文地址:http://www.cnblogs.com/xiaomixia/p/7170555.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!