您不需要將您的unix時間戳轉換爲ISO。哈爾發佈了一段代碼,修改了jQuery的timeago plugin,這對我很有幫助。只需在89線與本替換TIMEAGO的parse()函數:
parse: function(iso8601) {
if ((iso8601 - 0) == iso8601 && iso8601.length > 0) { // Checks if iso8601 is a unix timestamp
var s = new Date(iso8601);
if (isNaN(s.getTime())) { // Checks if iso8601 is formatted in milliseconds
var s = new Date(iso8601 * 1000); //if not, add milliseconds
}
return s;
}
var s = $.trim(iso8601);
s = s.replace(/-/,"/").replace(/-/,"/");
s = s.replace(/T/," ").replace(/Z/," UTC");
s = s.replace(/([\+-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400
return new Date(s);
},
jQuery Time ago from a timestamp?
我不明白這是什麼都有用jQuery做。你在尋找客戶端方法(JavaScript)還是服務器端方法(Python)? – 2010-09-21 00:00:29