本文整理汇总了PHP中time_ago函数的典型用法代码示例。如果您正苦于以下问题:PHP time_ago函数的具体用法?PHP time_ago怎么用?PHP time_ago使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了time_ago函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render_chat_messages
/**
* Render the div full of chat messages.
* @param $chatlength Essentially the limit on the number of messages.
**/
function render_chat_messages($chatlength, $show_elipsis = null)
{
// Eventually there might be a reason to abstract out get_chats();
$sql = new DBAccess();
$sql->Query("SELECT sender_id, uname, message, age(now(), date) as ago FROM chat join players on chat.sender_id = player_id ORDER BY chat_id DESC LIMIT {$chatlength}");
// Pull messages
$chats = $sql->fetchAll();
$message_rows = '';
$messageCount = $sql->QueryItem("select count(*) from chat");
if (!isset($show_elipsis) && $messageCount > $chatlength) {
$show_elipsis = true;
}
$res = "<div class='chatMessages'>";
$previous_date = null;
$skip_interval = 3;
// minutes
foreach ($chats as $messageData) {
$l_ago = time_ago($messageData['ago'], $previous_date);
$message_rows .= "<li><<a href='player.php?player_id={$messageData['sender_id']}'\n\t\t target='main'>{$messageData['uname']}</a>> " . out($messageData['message']) . " <span class='chat-time'>{$l_ago}</span></li>";
$previous_date = $messageData['ago'];
// Store just prior date.
}
$res .= $message_rows;
if ($show_elipsis) {
// to indicate there are more chats available
$res .= ".<br>.<br>.<br>";
}
$res .= "</div>";
return $res;
}
示例2: Hace
/**
* @link http://css-tricks.com/snippets/php/time-ago-function/
* @param String
* @return string
*/
public function Hace($diahora)
{
$rcs = 0;
$tm = is_int($diahora) ? $diahora : strtotime($diahora);
$curTm = time();
$dif = $curTm - $tm;
$negativo = false;
if ($dif < 0) {
$dif = $dif * -1;
$negativo = true;
}
$pds = array('seg', 'min', 'hour', 'day', 'week', 'month', 'year', 'decade');
//$pds = array('segundo', 'minuto', 'hora', 'día', 'semana', 'mes', 'año', 'década');
$lngh = array(1, 60, 3600, 86400, 604800, 2630880, 31570560, 315705600);
for ($v = sizeof($lngh) - 1; $v >= 0 && ($no = $dif / $lngh[$v]) <= 1; $v--) {
}
if ($v < 0) {
$v = 0;
}
$_tm = $curTm - $dif % $lngh[$v];
$no = floor($no);
if ($no != 1) {
$pds[$v] .= substr($pds[$v], -1) == 's' ? 'es' : 's';
}
$x = sprintf("%d %s ", $no, $pds[$v]);
if ($rcs == 1 && $v >= 1 && $curTm - $_tm > 0) {
$x .= time_ago($_tm);
}
if ($negativo) {
return "-" . $x;
}
return $x;
}
示例3: showDate
function showDate($date)
{
$stf = 0;
$current_time = time();
$diff = $current_time - $date;
$seconds = array('секунду', 'секунды', 'секунд');
$minutes = array('минуту', 'минуты', 'минут');
$hours = array('час', 'часа', 'часов');
$days = array('день', 'дня', 'дней');
$weeks = array('неделю', 'недели', 'недель');
$months = array('месяц', 'месяца', 'месяцев');
$years = array('год', 'года', 'лет');
$phrase = array($seconds, $minutes, $hours, $days, $weeks, $months, $years);
$length = array(1, 60, 3600, 86400, 604800, 2630880, 31570560);
for ($i = sizeof($length) - 1; $i >= 0 && ($no = $diff / $length[$i]) <= 1; $i--) {
}
if ($i < 0) {
$i = 0;
}
$_time = $current_time - $diff % $length[$i];
$no = floor($no);
$value = sprintf("%d %s ", $no, getPhrase($no, $phrase[$i]));
if ($stf == 1 && $i >= 1 && $current_time - $_time > 0) {
$value .= time_ago($_time);
}
if (strCaseCmp($value, '1 день ') == 0) {
return 'вчера';
} else {
return $value . ' назад';
}
}
示例4: timeFromPublish
function timeFromPublish($tm, $rcs = 0)
{
$cur_tm = time();
$dif = $cur_tm - $tm;
$lngh = array(1, 60, 3600, 86400, 604800, 2630880, 31570560, 315705600);
for ($v = sizeof($lngh) - 1; $v >= 0 && ($no = $dif / $lngh[$v]) <= 1; $v--) {
}
if ($v < 0) {
$v = 0;
$_tm = $cur_tm - $dif % $lngh[$v];
}
$no = floor($no);
$useName = $this->timeNames[$v];
if ($no != 1) {
if ($useName == "mes") {
$useName .= 'es';
} else {
$useName .= 's';
}
}
$x = sprintf("%d %s ", $no, $useName);
if ($rcs == 1 && $v >= 1 && $cur_tm - $_tm > 0) {
$x .= time_ago($_tm);
}
return $x;
}
示例5: site_getinfo
/**
* @return mixed
*/
function site_getinfo()
{
$site = elgg_get_config('site');
$siteinfo['url'] = elgg_get_site_url();
$siteinfo['sitename'] = $site->name;
$siteinfo['logo'] = elgg_get_plugin_setting('ws_get_logo', 'elgg_with_rest_api');
if ($site->description == null) {
$siteinfo['description'] = '';
} else {
$siteinfo['description'] = $site->description;
}
$siteinfo['time_created'] = time_ago($site->time_created);
$siteinfo['language'] = elgg_get_config('language');
return $siteinfo;
}
示例6: index
function index()
{
$h = new History();
$events = $h->include_related('user')->order_by('id DESC')->get_iterated();
foreach ($events as $e) {
$message = unserialize($e->message);
if (is_string($message)) {
$message = $this->messages[$message];
} else {
$key = array_shift($message);
$message = vsprintf($this->messages[$key], $message);
}
echo $message . ' by ' . $e->user_username . ' ' . time_ago($e->created_on) . '<br>';
}
exit;
}
示例7: time_ago
function time_ago($tm, $rcs = 0)
{
$cur_tm = time();
$dif = $cur_tm - $tm;
$pds = array('s', 'm', 'h', 'd', 'w');
$lngh = array(1, 60, 3600, 86400, 604800);
for ($v = sizeof($lngh) - 1; $v >= 0 && ($no = $dif / $lngh[$v]) <= 1; $v--) {
}
if ($v < 0) {
$v = 0;
}
$_tm = $cur_tm - $dif % $lngh[$v];
$x = sprintf("%d%s ", $no, $pds[$v]);
if ($rcs == 1 && $v >= 1 && $cur_tm - $_tm > 0) {
$x .= time_ago($_tm);
}
return $x;
}
示例8: get_comments
function get_comments($post_id)
{
$comment = array();
$sql = "SELECT * FROM pb_comments WHERE post_id='{$post_id}'";
$conn = new mysqli(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_NAME);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while ($val = $result->fetch_assoc()) {
$user_data = json_decode(pb_table_data('pb_users', 'user_data', "user_id='+{$val['author']}'"), true);
$item = array('id' => $val['id'], 'date' => $val['date'], 'timestamp' => array('date' => $val['date'], 'laps' => time_ago(strtotime($val['date']))), 'user' => array('id' => $val['author'], 'name' => $user_data[0]['name'], 'username' => $user_data[0]['username'], 'avatar' => $user_data[0]['avatar']), 'status' => $val['status'], 'comment' => $val['comment']);
array_push($comment, $item);
}
}
$conn->close();
return json_encode($comment);
}
示例9: render_message
function render_message($message_row, $show_buttons = true, $selected = false)
{
if (isset($_SESSION["user_id"])) {
// set a class based on the readflag
$readflag_class = $message_row["ReadFlag"] == 1 ? "read" : "";
$selected_class = $selected ? "selected" : "";
$avatar_image = $message_row["FromUsersAvatar"] != "" ? $message_row["FromUsersAvatar"] : "avatars/generic_64.jpg";
$meta = "<div class=\"avatar\"><a href=\"/" . $message_row["FromUsersUsername"] . "\" title=\"" . $message_row["FromUsersUsername"] . "\"><img src=\"/" . $avatar_image . "\" width=\"32\" height=\"32\" alt=\"" . $message_row["FromUsersUsername"] . "\" /></a></div>\n" . "<div class=\"meta\">\n" . "<div class=\"username\">from <a href=\"/" . $message_row["FromUsersUsername"] . "\" title=\"" . $message_row["FromUsersUsername"] . "\">" . $message_row["FromUsersUsername"] . "</a> to <a href=\"/" . $message_row["ToUsersUsername"] . "\" title=\"" . $message_row["ToUsersUsername"] . "\">" . $message_row["ToUsersUsername"] . "</a></div>\n" . "<div class=\"data\">" . ($message_row["Type"] == 0 ? "<a href=\"/message/" . $message_row["Id"] . "\">" . time_ago($message_row["Created"]) . "</a>" : time_ago($message_row["Created"])) . ($message_row["ParentMessagesId"] != null ? " in response to a <a href=\"/message/" . $message_row["ParentMessagesId"] . "\">message</a> by <a href=\"/" . $message_row["ParentUsersUsername"] . "\">" . $message_row["ParentUsersUsername"] . "</a>" : "") . "</div>\n" . "</div> <!-- .meta -->\n";
// work out the remove button (remove, or restore)
$remove_restore_button = "";
if ($message_row["ToUserId"] == $_SESSION["user_id"] && $message_row["ToStatus"] == 0 || $message_row["FromUserId"] == $_SESSION["user_id"] && $message_row["FromStatus"] == 0) {
$remove_restore_button = "<div class=\"button\"><a href=\"/api/message/remove/" . $message_row["Id"] . "\" title=\"Remove\" onclick=\"return confirm('Are you sure?');\">Remove</a></div>";
} else {
$remove_restore_button = "<div class=\"button\"><a href=\"/api/message/restore/" . $message_row["Id"] . "\" title=\"Restore\" onclick=\"return confirm('Are you sure?');\">Restore</a></div>";
}
$html = "<div class=\"message_wrapper\">\n" . "<div class=\"message " . $readflag_class . " " . $selected_class . "\">\n" . "<div class=\"body\">" . Markdown($message_row["Body"]) . "</div>\n" . "<div class=\"info\">\n" . ($show_buttons ? ($message_row["ToUserId"] == $_SESSION["user_id"] && $message_row["Type"] == 0 ? "<div class=\"button\"><a href=\"/messages/compose/" . $message_row["FromUsersUsername"] . "/" . $message_row["Id"] . "/#form\" title=\"Reply\">Reply</a></div>" : "") . $remove_restore_button : "") . $meta . "<div class=\"clear\"></div>\n" . "</div> <!-- .info -->\n" . "</div> <!-- .message -->\n" . "</div> <!-- .message_wrapper -->\n\n";
return $html;
}
}
示例10: rkv_ago
function rkv_ago($tm, $rcs = 0)
{
$cur_tm = time();
$dif = $cur_tm - $tm;
$pds = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year', 'decade');
$lngh = array(1, 60, 3600, 86400, 604800, 2630880, 31570560, 315705600);
for ($v = sizeof($lngh) - 1; $v >= 0 && ($no = $dif / $lngh[$v]) <= 1; $v--) {
}
if ($v < 0) {
$v = 0;
}
$_tm = $cur_tm - $dif % $lngh[$v];
$no = floor($no);
if ($no != 1) {
$pds[$v] .= 's';
}
$x = sprintf("%d %s ", $no, $pds[$v]);
if ($rcs == 1 && $v >= 1 && $cur_tm - $_tm > 0) {
$x .= time_ago($_tm);
}
return $x;
}
示例11: wk_twitter
/**
* Fetches and displays twitter messages
*
* @example wk_twitter('en', 'TechblogGR', 3, '<h3>Twitter</h3><ul>', '</ul>', '<li>the_twit @ the_time</li>', 60);
*
* @return The twits
* @param string $language
* @param string $username
* @param int $messages[optional]
* @param string $prefix[optional]
* @param string $suffix[optional]
* @param string $between[optional] Using the vars: the_twit, the_time
* @param int $update_time[optional]
*/
function wk_twitter($language, $username, $messages = 1, $prefix = '', $suffix = '', $between = '', $update_time = 15)
{
//languages
if ($language == 'en') {
$ago = 'ago';
} elseif ($language == 'gr') {
$ago = 'πριν';
}
//include necessary files
include_once 'time_ago.php';
//fetch data from database
//data in db are saved like that: updated_time . '~' . $alltwits . '~' . $alltimes
$data = get_option('wk_twitter');
//seperate to time, twits, times
$data = explode('~', $data);
$updated_time = $data[0];
//seperate twits
$mytwits = explode('|', $data[1]);
//seperate times
$mytimes = explode('|', $data[2]);
//calculate current time
$mytime = date('G') * 60 + date('i');
//check if we should update twits
if ($mytime > $updated_time + $update_time || $mytime + $update_time < $updated_time) {
include_once 'update.php';
wk_twitter_update($username, $messages);
}
//create final string
$final = $prefix;
for ($i = 0; $i < $messages; $i++) {
//replace dummy vars with the real ones
$temp = str_replace('the_twit', $mytwits[$i], $between);
$temp = str_replace('the_time', time_ago($mytimes[$i], $language) . " {$ago}", $temp);
$final .= $temp;
}
$final .= $suffix;
echo $final;
}
示例12: ShowDate
function ShowDate($timestamp)
{
$stf = 0;
$cur_time = time();
$diff = $cur_time - $timestamp;
$phrase = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year', 'decade');
$length = array(1, 60, 3600, 86400, 604800, 2630880, 31570560, 315705600);
for ($i = sizeof($length) - 1; $i >= 0 && ($no = $diff / $length[$i]) <= 1; $i--) {
}
if ($i < 0) {
$i = 0;
}
$_time = $cur_time - $diff % $length[$i];
$no = floor($no);
if ($no != 1) {
$phrase[$i] .= 's';
}
$value = sprintf("%d %s ", $no, $phrase[$i]);
if ($stf == 1 && $i >= 1 && $cur_tm - $_time > 0) {
$value .= time_ago($_time);
}
return $value . ' ago ';
}
示例13: hace
/**
* @link http://css-tricks.com/snippets/php/time-ago-function/
* @param String
* @return string
*/
public static function hace($diahora)
{
$rcs = 0;
$tm = strtotime($diahora);
$cur_tm = time();
$dif = $cur_tm - $tm;
$pds = array('segundo', 'minuto', 'hora', 'dia', 'semana', 'mes', 'año', 'decada');
$lngh = array(1, 60, 3600, 86400, 604800, 2630880, 31570560, 315705600);
for ($v = sizeof($lngh) - 1; $v >= 0 && ($no = $dif / $lngh[$v]) <= 1; $v--) {
}
if ($v < 0) {
$v = 0;
}
$_tm = $cur_tm - $dif % $lngh[$v];
$no = floor($no);
if ($no != 1) {
$pds[$v] .= substr($pds[$v], -1) == 's' ? 'es' : 's';
}
$x = sprintf("%d %s ", $no, $pds[$v]);
if ($rcs == 1 && $v >= 1 && $cur_tm - $_tm > 0) {
$x .= time_ago($_tm);
}
return 'hace ' . $x;
}
示例14: ot_get_option
<?php
$newscategory = ot_get_option('news-category');
$categorynum = ot_get_option('news-category-num');
$queryObject = new WP_query(array('category__and' => $newscategory, 'posts_per_page' => $categorynum));
if ($queryObject->have_posts()) {
while ($queryObject->have_posts()) {
$queryObject->the_post();
?>
<li><a href="<?php
the_permalink();
?>
"><span><time class="post_date date updated" datetime="<?php
the_time('j M, Y');
?>
"><?php
echo time_ago();
?>
</time></span> <b class="post-title entry-title"><?php
the_title();
?>
</b> </a></li>
<?php
}
}
wp_reset_query();
?>
</ul><!-- /ticker -->
<?php
} elseif (ot_get_option('breaking-or-menu') === '2') {
?>
<nav id="mymenutwo">
示例15: foreach
foreach ($user_data as $data) {
$author = $data['name'];
$user = $data['username'];
$avatar = $data['avatar'];
}
if (isset($_GET['timeago'])) {
$val['date'] = time_ago(strtotime($val['date']));
}
$entity = array('id' => $val['id'], 'post_id' => $val['post_id'], 'date' => $val['date'], 'author' => $val['author'], 'user' => array('name' => $author, 'username' => $user, 'avatar' => $avatar), 'status' => $val['status'], 'comment' => $val['comment']);
array_push($mainJson, $entity);
}
// end pb_comments
//pb_users
if ($slq_table == 'pb_users') {
if (isset($_GET['timeago'])) {
$val['date'] = time_ago(strtotime($val['date']));
}
$entity = array('user_id' => $val['user_id'], 'username' => $val['username'], 'num_of_ratings' => $val['num_of_ratings'], 'total_ratings' => $val['total_ratings'], 'permissions' => $val['permissions'], 'id_card_key' => $val['id_card_key'], 'contact_info' => json_decode($val['contact_info']), 'user_data' => json_decode($val['user_data']));
array_push($mainJson, $entity);
}
// end pb_users
//pb_tags
if ($slq_table == 'pb_tags') {
$entity = array('id' => $val['tag_id'], 'tag' => $val['tag'], 'count' => $val['count']);
array_push($mainJson, $entity);
}
// end pb_tags
//pb_notify
if ($slq_table == 'pb_notify') {
$entity = array('id' => $val['id'], 'to' => $val['notify_to'], 'from' => $val['notify_from'], 'item' => $val['item'], 'item' => $val['item'], 'intro' => $val['intro'], 'content' => $val['content'], 'link' => $val['link'], 'date' => $val['date'], 'seen' => $val['seen']);
array_push($mainJson, $entity);