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

时间:2014-02-15 09:12:53

标签: cakephp-2.0

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

例如:

about one week ago

而不是

1 week, 2 days ago

1 个答案:

答案 0 :(得分:0)

根据您的需要创建自己的方法来处理它。您可以实现this

之类的int_to_words()函数

类似的东西:

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...
}