Home > php教程 > php手册 > PHP获取当前时间的毫秒数

PHP获取当前时间的毫秒数

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 19:46:37
Original
1784 people have browsed it

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 PHP的毫秒是没有默认函数的,但提供了一个microtime()函数,该函数返回包含两个元素,一个是秒数,一个是小数表示的毫秒数,借助此函数,可以很容易定义一个返回毫秒数的函数,例如: /* * microse

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  PHP的毫秒是没有默认函数的,但提供了一个microtime()函数,该函数返回包含两个元素,一个是秒数,一个是小数表示的毫秒数,借助此函数,可以很容易定义一个返回毫秒数的函数,例如:

  /*

  * microsecond 微秒     millisecond 毫秒

  *返回时间戳的毫秒数部分

  */

  function get_millisecond()

  {

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

  $msec=round($usec*1000);

  return $msec;

  }

  /*

  *

  *返回字符串的毫秒数时间戳

  */

  function get_total_millisecond()

  {

  $time = explode (" ", microtime () );

  $time = $time [1] . ($time [0] * 1000);

  $time2 = explode ( ".", $time );

  $time = $time2 [0];

  return $time;

  }

  /*

  *

  *返回当前 Unix 时间戳和微秒数(用秒的小数表示)浮点数表示,常用来计算代码段执行时间

  */

  function microtime_float()

  {

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

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

  }

  需要注意,在32位系统中PHP的int最大值远远小于毫秒数,所以不能使用int类型,而php中没有long类型,所以只好使用浮点数来表示。

PHP获取当前时间的毫秒数

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template