开发者

Informal PHP date output library

is there a library out there for PHP that formats dates in an informal way?

开发者_JS百科

I would love to have outputs like yesterday, 2 minutes ago, just now, three weeks ago – just like in Facebook. Makes blog posts appear so much more human.

Thanks in advance for your help.


I dunno about a library, but plenty of snippet functions:

http://urbanoalvarez.es/blog/2009/01/20/display-time-since-last-visit-in-php/

http://binarybonsai.com/code/timesince.txt

The keywords are time since php and should pull up tons of snippets / code for you.


Not sure about php but there's a jQuery plugin that does just that jQuery Pretty Date

Makes it easier to dynamically update the output, ie when a user stays on page for some time, the 2 minutes ago would update to say 3 minutes ago and so on

Example straight from that website

prettyDate("2008-01-28T20:24:17Z") // => "2 hours ago"
prettyDate("2008-01-27T22:24:17Z") // => "Yesterday"
prettyDate("2008-01-26T22:24:17Z") // => "2 days ago"
prettyDate("2008-01-14T22:24:17Z") // => "2 weeks ago"
prettyDate("2007-12-15T22:24:17Z") // => undefined 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜