Created
June 4, 2015 02:42
-
-
Save davewang/8bbea5b83985bbd69e6f to your computer and use it in GitHub Desktop.
timeago translate for wordpress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function timeago(ptime) | |
local etime =os.time() - ptime | |
if (etime < 1) then | |
return '刚刚' | |
end | |
local interval_ = { | |
{secs = 12 * 30 * 24 * 60 * 60,str=os.date('年前', ptime)} , | |
{secs = 30 * 24 * 60 * 60 ,str=os.date('个月前', ptime)} , | |
{secs = 7 * 24 * 60 * 60 ,str=os.date('周前', ptime)}, | |
{secs = 24 * 60 * 60 ,str='天前'}, | |
{secs = 60 * 60 ,str='小时前'}, | |
{secs = 60 ,str='分钟前'}, | |
{secs = 1 ,str='秒前'} | |
} | |
for i=1,#interval_ do | |
local d = etime/interval_[i].secs | |
if d >= 1 then | |
return math.floor(d)..interval_[i].str | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment