Skip to content

Instantly share code, notes, and snippets.

@wjx0912
Created November 2, 2021 06:14
Show Gist options
  • Save wjx0912/9eb378e71ea85fccb3151b8eb5a19729 to your computer and use it in GitHub Desktop.
Save wjx0912/9eb378e71ea85fccb3151b8eb5a19729 to your computer and use it in GitHub Desktop.
javascript print date&time (yyyy-mm-dd hh:mm:ss:SS)
function getNowTime() {
var d = new Date;
var dformat =
[
d.getFullYear(),
("00" + (d.getMonth()+1)).slice(-2),
("00" + d.getDate()).slice(-2)
].join('-')
+ ' '
+ [
("00" + d.getHours()).slice(-2),
("00" + d.getMinutes()).slice(-2),
("00" + d.getSeconds()).slice(-2),
("000" + d.getMilliseconds()).slice(-3)
].join(':');
return dformat;
}
console.log(getNowTime());
@wjx0912
Copy link
Author

wjx0912 commented Nov 2, 2021

output:
"2021-11-02 14:09:05:370"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment