Created
November 9, 2009 02:39
-
-
Save lolicsystem/229632 to your computer and use it in GitHub Desktop.
This file contains 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
<html> | |
<head> | |
<title>クロージャを使って、今日昨日明日の日付を表示</title> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
function date_string() { | |
var nt = new Date(); | |
var now = nt.getTime(); | |
return function (offset) { | |
var uYear, uMon, uDate; | |
nt.setTime(now + offset * 86400000); | |
uYear = ("00" + (nt.getYear() - 100).toString()).slice(-2); | |
uMon = ("00" + (nt.getMonth() + 1).toString()).slice(-2); | |
uDate = ("00" + nt.getDate() .toString()).slice(-2); | |
var uDate = uYear + uMon + uDate; | |
return uDate; | |
} | |
} | |
var dt = date_string(); | |
alert(dt(0)); // 今日 | |
alert(dt(-1)); // 昨日 | |
alert(dt(1)); // 明日 | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment