I am querying facebook graph api. It returns date in following format: 2012-01-23T23:52:29+0000.
I need to find difference of dates of this type in javascript. It’s not a valid date in javascript ( by Date.parse() or new Date() )
I am thinking of replacing 'T' with ' ' (a space), '-' with '/' and '+0000' with '' (empty string). Is this the only way? Or am I missing something here?
Also, if this is the only way, can someone give me a regex to replace all in one go?
Execution speed is my main concern.
I’d say yes to replacing
-with/, since that’s that the ISO-whatever standard dictates (Facebook likes to screw things around, like<meta>tags withpropertyattributes instead ofnamelike they should be).Keep the timezone part, since JS understands that and will handle it accordingly.
Overall, you want
new Date(input.replace(/-/g,'/'));.In response to comments, a better (more complete) solution would be: