Christine Stringfield
Posts: 0
Joined: Wed Apr 03, 2013 4:35 am

Javascript Date() on _createdAt field returns Invalid Date

Hello,

I have some Javascript I am trying to use to convert the _createdAt timestamp to something more readable. However if I take the value and pass it into new Date(value) it returns "Invalid Date". I know that the value (ie 2013-04-25 02:02:35.655) is getting passed into the function.

Here is my code:

var date = new Date(value);
alert(date);
var hour = date.getHours()-7;
date.setHours(hour);
var diff = (((new Date()).getTime() - date.getTime()) / 1000);
var day_diff = Math.floor(diff / 86400);

if ( isNaN(day_diff) day_diff < 0 day_diff = 31 )
{
return;
}
else
{
return day_diff == 0 && (
diff < 60 && "just now"
diff < 120 && "1 minute ago"
diff < 3600 && Math.floor( diff / 60 ) + " minutes ago"
diff < 7200 && "1 hour ago"
diff < 86400 && Math.floor( diff / 3600 ) + " hours ago")
day_diff == 1 && "Yesterday"
day_diff < 7 && day_diff + " days ago" ||
day_diff < 31 && Math.ceil( day_diff / 7 ) + " weeks ago";
}

Christine Stringfield
Posts: 0
Joined: Wed Apr 03, 2013 4:35 am

Javascript Date() on _createdAt field returns Invalid Date

I noticed that this works fine in Chrome but not in Firefox. Do you have any suggestions for getting the _createdAt date into a format that will be compatible with the Date() function?

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Javascript Date() on _createdAt field returns Invalid Date

Check/debug where exactly (what line) it fails in Firefox. It's interesting.. but looks like there are differences in implementation between Chrome and Firefox. You could also visit Firefox dev. site to see if there is a solution to this.

Return to “Issues”