0

成功関数内に投稿された時間を必要とする投稿があります。私の元のリンクは、phpの場合は次のようになります。

echo "<br/><a href='#' class='subtleLink' style='font-weight:normal;'>".Agotime($streamitem_data['streamitem_timestamp'])."</a>";

そして、私はajaxを構築していて、成功関数ではAgotimeも追加する必要がありますが、その方法がわかりません。タイムスタンプには、関数Agotimeがその処理を実行するために必要なものがあります。

AJAX

  <br/><a class='subtleLink' style='font-weight:normal;'>"+response['streamitem_timestamp']+"</a>

MyAgotimeは関数です

 function Agotime($date)
{
    if(empty($date)) {
        return "No date provided";
    }

    $periods         = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
    $lengths         = array("60","60","24","7","4.35","12","10");

    $now             = time();
    $unix_date       = strtotime($date);

       // check validity of date
    if(empty($unix_date)) {    
        return "Bad date";
    }

    // is it future date or past date
    if($now > $unix_date) {    
        $difference     = $now - $unix_date;
        $tense         = "ago";

    } else {
        $difference     = $unix_date - $now;
        $tense         = "from now";
    }

    for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
        $difference /= $lengths[$j];
    }

    $difference = round($difference);

    if($difference != 1) {
        $periods[$j].= "s";
    }

    return "$difference $periods[$j] {$tense}";
}
?>
4

1 に答える 1

0

私はそれを理解しました。Ajaxが呼び出しを行うときのために、挿入ページにAgotimeを追加しました。魅力的に動作します。

$json = array();
$check = "SELECT streamitem_id, streamitem_timestamp FROM streamdata";
$check1 = mysql_query($check);
$resultArr = mysql_fetch_array($check1);
$json['streamitem_id'] = $resultArr['streamitem_id'];
$json['streamitem_timestamp'] = Agotime($resultArr['streamitem_timestamp']);
于 2012-08-03T09:42:04.313 に答える