Last active
December 17, 2015 14:39
-
-
Save shunjikonishi/5626130 to your computer and use it in GitHub Desktop.
yyyy-MM-dd HH:mm:ss形式のstrToDateとdateToStr
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 strToDate(str) { | |
var y = parseInt(str.substring(0, 4)), | |
m = parseInt(str.substring(5, 7)), | |
d = parseInt(str.substring(8, 10)), | |
h = parseInt(str.substring(11, 13)), | |
mi = parseInt(str.substring(14, 16)), | |
s = parseInt(str.substring(17, 19)), | |
ms = 0; | |
return new Date(y, m - 1, d, h, mi, s, ms); | |
} | |
function dateToStr(d) { | |
function pad(n) { | |
return n < 10 ? "0" + n : "" + n; | |
} | |
return d.getFullYear() + "-" + | |
pad(d.getMonth() + 1) + "-" + | |
pad(d.getDate()) + " " + | |
pad(d.getHours()) + ":" + | |
pad(d.getMinutes()) + ":" + | |
pad(d.getSeconds()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment