Reputation: 965
I have a date like 2012-08-09T20:37:52.041 i want to subtract this time from the current time. To use the getTime() function and subtract the time i need this time in a parsable format. How do I do that? Or is there any other way to subtract a time like 2012-08-09T20:37:52.041 from the current time?
Upvotes: 0
Views: 216
Reputation: 57719
It's really super hard to parse dates in JavaScript.
var datestring = "2012-08-09T20:37:52.041";
var date = new Date(datestring);
var diff = (new Date()).getTime() - date.getTime(); // in milliseconds
I'm joking, it's super easy.
Upvotes: 1
Reputation: 3106
Use a date parsing library like http://www.datejs.com/. With that, you can do this:
Date.parse('2012-08-09T20:37:52') // You'll have to remove the milliseconds
Upvotes: 2