使用原始的John Resig prettyDate脚本here
问题:如果你在美国,澳大利亚的日期是29/9/2014或9/29/2014格式
我这次提供了prettyDate格式:
prettyDate("2014-09-27T06:24:17Z")
它返回:
Yesterday
它应该说" 2天前"
错误的原因是什么时候关闭1天?
如果我在今天早上29点6分喂它:
prettyDate("2014-09-29T06:00:17Z")
它不会返回任何空白。 这是代码可以有人想出来的吗?是的,系统托盘时钟中的日期是在29/9/2014设置的。
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";
}
// If jQuery is included in the page, adds a jQuery plugin to handle it as well
if ( typeof jQuery != "undefined" )
jQuery.fn.prettyDate = function(){
return this.each(function(){
var date = prettyDate(this.title);
if ( date )
jQuery(this).text( date );
});
};