Created
January 28, 2013 16:44
-
-
Save codexico/4657089 to your computer and use it in GitHub Desktop.
date utils
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
//http://stackoverflow.com/questions/7388001/javascript-regex-to-validate-date | |
//http://jsfiddle.net/mplungjan/Mqh8D/ | |
var isDate = function (str) { | |
var parms = str.split(/[\.\-\/]/); | |
var yyyy = parseInt(parms[2],10); | |
var mm = parseInt(parms[1],10); | |
var dd = parseInt(parms[0],10); | |
var date = new Date(yyyy,mm-1,dd,0,0,0,0); | |
return mm === (date.getMonth()+1) && dd === date.getDate() && yyyy === date.getFullYear(); | |
} | |
var stringToDate = function (str) { | |
var parms = str.split(/[\.\-\/]/); | |
var yyyy = parseInt(parms[2],10); | |
var mm = parseInt(parms[1],10); | |
var dd = parseInt(parms[0],10); | |
return new Date(yyyy,mm-1,dd,0,0,0,0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment