Dec 16 2007

js显示相对时间

Posted by admin

TYPO的show_dates_as_local_time()函数是用来显示相对的发贴时间。
首先链接typo.js

<%= javascript_include_tag "typo" %>

在application的help里添加

def js_distance_of_time_in_words_to_now(date)
time = date.utc.strftime("%a, %d %b %Y %H:%M:%S GMT")
"<span class=\"typo_date\" title=\"#{time}\">#{time}</span>"
End

View里

<%= js_distance_of_time_in_words_to_now(date) %>


<script type="text/javascript">
//<![CDATA[
show_dates_as_local_time()
//]]>
</script>

OK,不过这js只显示8星期内的相对时间,超过则显示为原始时间。

Filed under : technology | No Comments »