如何在php中使用时间函数

  介绍

如何在php中使用时间函数?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

php中有unix时间戳的相关操作函数,使用很方便

时间()返回当前的unix时间戳

microtime——返回当前unix时间戳和微秒数

1例。用microtime()对脚本的运行计时

& lt; php ?/* *   *,Simple  function 用replicate  PHP  5,行为   */function  microtime_float ()   {   ,,列表(sec)美元购买美元,,,=,爆炸(“,“,,());   return 才能;((浮动)usec 美元;+,sec)美元(浮动);   }   $ time_start =, microtime_float ();//,Sleep  for  a    usleep (100);   $ time_end =, microtime_float ();   $ time =, time_end 美元;作用;time_start美元;   echo “Did  nothing  time 美元;拷贝秒/n";   ?在

mktime()取得一个日期的Unix时间戳

int mktime ([int小时[,int [int二[int月[,int [, int [int is_dst]]]]]]])

参数可以从右向左省略,任何省略的参数会被设置成本地日期和时间的当前值

日期()格式化一个本地时间/日期

日期字符串(字符串格式(int时间戳))

提示:自PHP 5.1起在$ _SERVER [& # 39; REQUEST_TIME& # 39;]中保存了发起该请求时刻的时间戳。

strtotime——将任何英文文本的日期时间描述解析为Unix时间戳

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

2例。某个时间的后一天,后一月

strtotime (“+ 1, day “天美元);   strtotime (“2008 - 01 - 31 -, + 1, month");   strtotime(美元一天!”,+ 1,day");

如何在php中使用时间函数