Skip to content

Instantly share code, notes, and snippets.

@jack-nie
Last active April 14, 2018 04:26
Show Gist options
  • Save jack-nie/9b9fea64292b914f7531c581f5aeb7d2 to your computer and use it in GitHub Desktop.
Save jack-nie/9b9fea64292b914f7531c581f5aeb7d2 to your computer and use it in GitHub Desktop.
javascript 获取当前时间
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