首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CakeTime相对时间而不是绝对时间

CakeTime相对时间而不是绝对时间
EN

Stack Overflow用户
提问于 2014-02-15 09:12:53
回答 1查看 46关注 0票数 0

如何使用CakeTime:timeAgoInWords获得相对时间而不是绝对时间?

例如:

代码语言:javascript
复制
about one week ago

而不是

代码语言:javascript
复制
1 week, 2 days ago
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-17 19:01:26

根据需要创建自己的方法来处理这些问题。还可以实现像int_to_words()这样的函数

类似于:

代码语言:javascript
复制
function relativeTime($time){
    $arrray = explode(" ",$time); // transform time in array of words
        if(array[1] == "week,"){
           if(array[2]) > 5){
               return "Almost two weeks ago";
           }
           return "About one week ago";
        }else if(array[1] == "weeks"){
           $aux = array[0];
           $number = int_to_words($aux);
           return "About $number week ago";
        }          
        // Read more about the possible CakeTime:timeAgoInWords results
        // and continue to implement the other possibilities here...
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21795577

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档