经常看见论坛或是微博的发布时间显示为,几秒前,几小时前,今天xx:xx,昨天xx:xx.....
应该有什么函数能快捷的计算出来这些吧,写一个觉得很麻烦,网上搜索又不知道怎么描述,所以希望哪个大侠给发一下此函数

解决方案 »

  1.   

    php没有这样的函数,需要你自己写
    以前我写过这个功能,就二三十来行代码而已。嫌麻烦还学编程
      

  2.   

    两天前$nowd = date("Ymd h:i:s");$arr[] = date("Ymd h:i:s",strtotime("-2 day $nowd"));
      

  3.   


    //两秒前
    $nowd = date("Ymd h:i:s");
    $arr[] = date("Ymd h:i:s",strtotime("-2 Second $nowd"));
      

  4.   

    $CurrentTime=getdate(); //取得当前时间数组
    $OldTime=strtotime($rw['lastdate']); //取得存在数据库中时间的Unix时间戳
    $TimeDifference=$CurrentTime[0]+(8*3600)-$OldTime;//把当前时间的Unix时间戳减去存在数据库中时间的Unix时间戳
    if($TimeDifference<60) //如果Unix时间戳小于60秒就显示多少秒前发布的{
    echo floor($TimeDifference)."秒前";
    }
    elseif($TimeDifference<3600) //如果Unix时间戳大于60秒小于3600秒就显示多少分钟前发布
    {
    $min=$TimeDifference/60; //时间戳差除以60得到多少分钟前
    echo floor($min)."分钟前";
      
    }
    else //否则按存在数据库中的格式显示时间
    {
      echo $rw['lastdate'];
    }
      

  5.   

            $time1 = $rows_arr['products_details_time'];//数据库保存时间
             $time2 = date("Y-m-d H:i:s");
            $cle = $time2 - $time1; //得出时间戳差值
             $d = floor($cle/3600/24);
            $h = floor(($cle-($d*3600*24))/3600);
            $m = floor(($cle-($d*3600*24)-($h*3600))/60);
            $str='';
            $str.=$d ? $d.'天' : '' ; 
            $str.=$h ? $h.'小时' : '' ;
            $str.=$m ? $m.'分钟' : '1分钟' ;          echo $str.'前';
      

  6.   

    用js语句写啊,能具体到日期星期几呢
    // JavaScript Document
    function initArray(){
    for(i=0;i<initArray.arguments.length;i++)
    this[i]=initArray.arguments[i];
    }
    var isnMonths=new initArray("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月");
    var isnDays=new initArray("星期日","星期一","星期二","星期三","星期四","星期五","星期六","星期日");
    today=new Date();
    hrs=today.getHours();
    min=today.getMinutes();
    sec=today.getSeconds();
    clckh=""+((hrs>12)?hrs-12:hrs);

    clckm=((min<10)?"0":"")+min;
    clcks=((sec<10)?"0":"")+sec;
    clck=(hrs>=12)?"下午":"上午";
    var stnr="";
    var ns="0123456789";
    var a="";
     
    function getFullYear(d){ //d is a date object
    yr=d.getYear();
    if(yr<1000) yr+=1900;
    return yr;
    }
     
    document.write(getFullYear(today)+"年"+isnMonths[today.getMonth()]+""+today.getDate()+"日 "+isnDays[today.getDay()]);