私は "2分前"、 "5日前"などのような社会的な方法として日付オブジェクトを表示するかなり日付jsを使用しています。しかし、それはクロームで動作しますが、なぜ私はjavascriptのnewbiewです原因を把握できません。 J.Resigのページからコードを取得し、私のニーズに合わせて修正しました。ここかなりの日付jsは、Firefoxで動作していません
は、すべてのコード
// Takes an ISO time and returns a string representing how
// long ago the date represents.
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 && "şimdi" ||
diff < 120 && "1 dk önce" ||
diff < 3600 && Math.floor(diff/60) + " dk önce" ||
diff < 7200 && "1 saat önce" ||
diff < 86400 && Math.floor(diff/3600) + " saat önce") ||
day_diff == 1 && "Dün" ||
day_diff < 7 && day_diff + " gün önce" ||
day_diff < 31 && Math.ceil(day_diff/7) + " hafta önce";
}
// Takes an ISO time and returns a string representing how
// long later the date represents.
function prettyReverseDate(time){
var date = new Date((time || "").replace(/-/g,"/").replace(/[TZ]/g," ")),
diff = ((date.getTime() - (new Date()).getTime())/1000),
day_diff = Math.floor(diff/86400);
//console.log("Day dif : " + day_diff);
if (isNaN(day_diff) || day_diff < 0 || day_diff >= 31)
return ;
//put what ever string you wanted like "Expirs in # hour/minute/day"
return day_diff == 0 && (
diff < 60 && " şimdi" ||
diff < 120 && " 1 dk" ||
diff < 3600 && Math.floor(diff/60) + " dakika" ||
diff < 7200 && " 1 saat" ||
diff < 86400 && Math.floor(diff/3600) + " saat") ||
day_diff == 1 && "1 gün" ||
day_diff < 7 && day_diff + " gün" ||
day_diff < 31 && Math.ceil(day_diff/7) + " hafta";
}
// 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);
else
jQuery(this).text("n/a");
});
};
// If jQuery is included in the page, adds a jQuery plugin to handle it as well
if (typeof jQuery != "undefined")
jQuery.fn.prettyReverseDate = function(){
return this.each(function(){
var date = prettyReverseDate(this.title);
if (date)
jQuery(this).text(date);
else
//make parent element show expired
jQuery(this).parent().text("süresi doldu");
});
};
確かに私はファイヤーバグを使用していますが、それは少し奇妙な私にエラーを表示しませんでした。私はLinux上でFirefoxのバージョン11を使用しています。あなたが見つけたエラーで私を助けることができるかもしれません。 –
prettyDateはFFで動作します私は過去にこのプラグインを使用していましたが、あなたはjavascriptのスキルを学び、デバッグにFirebugを使用する方法を学ぶ必要があります。 – Sam