奶头挺立呻吟高潮av全片,成人试看120秒体验区,性欧美极品v,A片高潮抽搐揉捏奶头视频

php語言

php實現求相對時間函數

時間:2025-02-21 11:29:08 php語言 我要投稿
  • 相關推薦

php實現求相對時間函數

  文章主要介紹了php實現求相對時間函數,可實現簡單求相對時間為幾分鐘前或幾小時前的功能,非常簡單實用,需要的朋友可以參考下。

php實現求相對時間函數

  1

  2

  3

  4

  5

  6

  7

  8

  9

  10

  11

  12

  13

  14

  15

  16

  17

  18

  19

  20

  21

  22

  23

  <?php

  function relativeTime($time = false, $limit = 86400, $format = 'g:i A M jS') {

  if (empty($time) || (!is_string($time) & amp; & amp;

  !is_numeric($time))) $time = time();

  elseif (is_string($time)) $time = strtotime($time);

  $now = time();

  $relative = '';

  if ($time === $now) $relative = 'now';

  elseif ($time > $now) $relative = 'in the future';

  else {

  $diff = $now - $time;

  if ($diff >= $limit) $relative = date($format, $time);

  elseif ($diff < 60) {

  $relative = 'less than one minute ago';

  } elseif (($minutes = ceil($diff / 60)) < 60) {

  $relative = $minutes . ' minute' . (((int)$minutes === 1) ? '' : 's') . ' ago';

  } else {

  $hours = ceil($diff / 3600);

  $relative = 'about ' . $hours . ' hour' . (((int)$hours === 1) ? '' : 's') . ' ago';

  }

  }

  return $relative;

  }

  希望本文所述對大家的php程序設計有所幫助。

  【拓展閱讀】

  php時間函數用法分析

  例 1. 用 microtime() 對腳本的運行計時

  ?

  1

  2

  3

  4

  5

  6

  7

  8

  9

  10

  11

  12

  13

  14

  15

  16

  <?php

  /**

  * Simple function to replicate PHP 5 behaviour

  */

  function microtime_float()

  {

  list($usec, $sec) = explode(" ", microtime());

  return ((float)$usec + (float)$sec);

  }

  $time_start = microtime_float();

  // Sleep for a while

  usleep(100);

  $time_end = microtime_float();

  $time = $time_end - $time_start;

  echo "Did nothing in $time seconds/n";

  ?>

  mktime()取得一個日期的 Unix 時間戳

  int mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] )

  參數可以從右向左省略,任何省略的參數會被設置成本地日期和時間的'當前值

  date()格式化一個本地時間/日期

  string date ( string format [, int timestamp] )

  提示: 自 PHP 5.1 起在 $_SERVER['REQUEST_TIME'] 中保存了發起該請求時刻的時間戳。

  strtotime -- 將任何英文文本的日期時間描述解析為 Unix 時間戳

  ?

  1

  2

  echo strtotime("+1 day"), "/n";

  echo strtotime("+1 week"), "/n";

  例2. 某個時間的后一天,后一月

  ?

  1

  2

  3

  strtotime("+1 day ".$day);

  strtotime("2008-01-31 +1 month");

  strtotime($day." +1 day");

【php實現求相對時間函數】相關文章:

php返回相對時間的方法06-01

php實現兼容2038年后Unix時間戳轉換函數09-26

php強大的時間轉換函數strtotime10-07

PHP時間和日期函數詳解10-17

php取得當前時間函數09-12

php的date()日期時間函數詳解11-12

PHP實現獲取FLV文件的時間07-27

php使用ftp函數實現簡單上傳功能10-31

php自定義函數實現漢字分割替換06-01

主站蜘蛛池模板: 定西市| 蒙自县| 竹北市| 游戏| 芒康县| 英德市| 钟祥市| 杭州市| 白水县| 遂川县| 霍城县| 玉山县| 荔波县| 柳河县| 揭西县| 建昌县| 隆回县| 崇文区| 阜宁县| 蕉岭县| 汉沽区| 镇平县| 安龙县| 松桃| 常山县| 安仁县| 澄城县| 丘北县| 左贡县| 荥经县| 墨竹工卡县| 澄迈县| 南江县| 会理县| 纳雍县| 临颍县| 阳泉市| 上高县| 无为县| 永济市| 囊谦县|