Created
April 9, 2014 03:41
-
-
Save cjwinchester/10224097 to your computer and use it in GitHub Desktop.
parse yyyymmdd date objects in javascript
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 parse(str) { | |
var y = str.substr(0,4), | |
m = str.substr(4,2) - 1, | |
d = str.substr(6,2); | |
var D = new Date(y,m,d); | |
return (D.getFullYear() == y && D.getMonth() == m && D.getDate() == d) ? D : ''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment