Reputation: 1967
I have this time stamp format for each car in my map:
2012-12-11T03:51:43+03:00
I want to extract the number of hours from it according to current time.
I don't know how to parse this string then compare it to current time.
Any Idea ?
Upvotes: 0
Views: 915
Reputation: 178109
You need to first fix the timestamp for other browsers than Chrome
javascript date.parse difference in chrome and other browsers
var noOffset = function(s) {
var day= s.slice(0,-5).split(/\D/).map(function(itm){
return parseInt(itm, 10) || 0;
});
day[1]-= 1;
day= new Date(Date.UTC.apply(Date, day));
var offsetString = s.slice(-5)
var offset = parseInt(offsetString,10)/100;
if (offsetString.slice(0,1)=="+") offset*=-1;
day.setHours(day.getHours()+offset);
return day.getTime();
}
alert(parseInt((new Date().getTime()-noOffset(yourTimeStamp))/3600000))
Upvotes: 0
Reputation: 54649
something like:
var
d1 = new Date('2012-12-11T03:51:43+03:00'),
d2 = new Date;
console.log(
(d2 - d1) / 3600000
);
Upvotes: 2