Skip to content

Instantly share code, notes, and snippets.

@jack-nie jack-nie/time.js
Last active Apr 14, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.