开发者

SO dates calculation and formatting

What script SO uses for dates d开发者_如何学编程isplaying? Because it seems to be pretty nice formatting and logical showing.


I am not sure what StackOverflow use. But one of the most common timestamp representaion is the one done by twitter which displays timestamp as a moment ago, 30 seconds ago, x minutes ago, yesterday, 10:30 PM Apr 12, 2010 etc. And it updates the timestamp every five seconds without hitting the server.

If you are interested you may look into John Resig's Pretty Date JS API. It's just awesome. Works with/without JQuery.

We tweaked it a bit to exactly match Twitter pattern. And it is awesome.


The website mentioned gives good example, but if you so want a working version, put the following script in address bar of any web-page. (you may want to tweak parameters passed to prettyDate function

  javascript:var i,s,ss=['http://ejohn.org/files/pretty.js'];for(i=0;i!=ss.length;i++){s=document.createElement('script');s.src=ss[i];document.body.appendChild(s);}alert("PrettyDate: "+(prettyDate("2011-03-13T03:24:17Z")?prettyDate("2011-03-13T03:24:17Z"):"03:24 AM Mar 13, 2011"));


I think it's based on the answers to this question on Stack Overflow asked by Jeff Atwood - most of the answers are in c# but there is a PHP implementation too

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜