Last active
April 14, 2018 04:26
-
-
Save jack-nie/9b9fea64292b914f7531c581f5aeb7d2 to your computer and use it in GitHub Desktop.
javascript 获取当前时间
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getNowFormatDate() { | |
var date = new Date(); | |
var dashSeperator = "-"; | |
var colonSeperator = ":"; | |
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 currentdate = date.getFullYear() + dashSeperator + month + dashSeperator + strDate | |
+ " " + date.getHours() + colonSeperator + date.getMinutes() | |
+ colonSeperator + date.getSeconds(); | |
return currentdate; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment