我正在使用 John Resig prettyDate 函数,以使其与具有这种格式的字符串一起工作:'2013-01-04 20:02:28'
但到目前为止我还没有成功......这个函数只适用于 iso datetimes..
function prettyDate(time){
var date = new Date((time || "").replace(/-/g,"/").replace(/[TZ]/g," ")),
diff = (((new Date()).getTime() - date.getTime()) / 1000),
day_diff = Math.floor(diff / 86400);
if ( isNaN(day_diff) || day_diff < 0 || day_diff >= 31 )
return;
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";
}
默认情况下,我的字符串的结果是:
>prettyDate('2013-01-04 20:02:28')
>undefined
拜托,有人可以帮我修改它以适应我的格式吗?谢谢。