Created
May 9, 2011 14:57
-
-
Save froop/962669 to your computer and use it in GitHub Desktop.
[JavaScript] 現在時刻取得(yyyy/mm/dd hh:mm:ss)
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
//現在時刻取得(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