I have this Twitter function with makes a link with the date the tweet was posted. It works in Firefox, Chrome, and Safari. IE though produces a wrong result: NaN or NaN days ago. The date coming into the function is formatted as such: Fri Apr 10:19:06 +0000 2012. Anyone have any thoughts?
html += '<a target="_blank" href="http://twitter.com/' + username + '#status_' + data[i].id_str + '">' + data[i].text + ' <i>' + Twitter.daysAgo(data[i].created_at) + '</i></a>';
daysAgo: function (date) {
var d = new Date(date).getTime();
var n = new Date().getTime();
var numDays = Math.round(Math.abs(n - d) / (1000 * 60 * 60 * 24));
var daysAgo = numDays + ' days ago';
if (numDays == 0) {
alert('Works 1');
daysAgo = 'today';
} else if (numDays == 1) {
alert('Works 2');
daysAgo = numDays + ' day ago';
}
return daysAgo;
I solved it by removing the timezone offset. Thu May 1- 13:51:30 +0000 2012 became Thu May 1- 13:51:30 2012 and that fixed the NaN error.