Created
March 27, 2012 17:17
-
-
Save ethertank/2218105 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
Date.prototype.getFormatDate = function getFormatDate() { | |
var d = this, | |
o = {}; | |
o.date = d; | |
o.json = d.toJSON(); | |
o.YYYY = d.getFullYear(); | |
o.M = d.getMonth() + 1; | |
o.D = d.getDate(); | |
o.wday = d.getDay(); | |
o.h = d.getHours(); | |
o.m = d.getMinutes(); | |
o.s = d.getSeconds(); | |
o.ms = d.getMilliseconds(); | |
o.MM = (o.M < 10) ? "0" + o.M : o.M; | |
o.DD = (o.D < 10) ? "0" + o.D : o.D; | |
o.hh = (o.h < 10) ? "0" + o.h : o.h; | |
o.mm = (o.m < 10) ? "0" + o.m : o.m; | |
o.ss = (o.s < 10) ? "0" + o.s : o.s; | |
return o; | |
} |
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
ゼロ埋めした月を MM とするなら、ゼロ埋めしたミリ秒はどうあらわすのがいいんだろう。 | |
あと曜日の書式も作っといても良いかも。Monday,MON,月 とかで返すやつ。 |
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
[object Object] | |
2012-03-27T17:16:46.544Z | |
2012 | |
3 | |
28 | |
水 | |
2 | |
16 | |
46 | |
544 | |
03 | |
28 | |
02 | |
16 | |
46 |
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
function echoArray(a) { | |
for (var i = 0, len = a.length; len > i; ++i) { | |
document.write(a[i] + "<br />"); | |
} | |
} | |
var d = new Date().getFormatDate(); | |
echoArray([ | |
d, | |
d.json, | |
d.YYYY, | |
d.M, | |
d.D, | |
["日", "月", "火", "水", "木", "金", "土"][d.wday], | |
d.h, | |
d.m, | |
d.s, | |
d.ms, | |
d.MM, | |
d.DD, | |
d.hh, | |
d.mm, | |
d.ss | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment