Skip to content

Instantly share code, notes, and snippets.

@froop
Created May 9, 2011 14:57
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save froop/962669 to your computer and use it in GitHub Desktop.
Save froop/962669 to your computer and use it in GitHub Desktop.
[JavaScript] 現在時刻取得(yyyy/mm/dd hh:mm:ss)
//現在時刻取得(yyyy/mm/dd hh:mm:ss)
function getCurrentTime() {
var now = new Date();
var res = "" + now.getFullYear() + "/" + padZero(now.getMonth() + 1) +
"/" + padZero(now.getDate()) + " " + padZero(now.getHours()) + ":" +
padZero(now.getMinutes()) + ":" + padZero(now.getSeconds());
return res;
}
//先頭ゼロ付加
function padZero(num) {
var result;
if (num < 10) {
result = "0" + num;
} else {
result = "" + num;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment