Created
June 6, 2016 10:48
-
-
Save hustcc/dfff33870aeea9e3b8b9f5965a441044 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
parse = function(input) { | |
if (input instanceof Date) { | |
return input; | |
} else if (!isNaN(input)) { | |
return new Date(input); | |
} else if (/^\d+$/.test(input)) { | |
return new Date(parseInt(input, 10)); | |
} else { | |
var s = (input || '').trim(); | |
s = s.replace(/\.\d+/, ''); // remove milliseconds | |
s = s.replace(/-/, '/').replace(/-/, '/'); | |
s = s.replace(/T/, ' ').replace(/Z/, ' UTC'); | |
s = s.replace(/([\+\-]\d\d)\:?(\d\d)/, ' $1$2'); // -04:00 -> -0400 | |
return new Date(s); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment