PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

gmdate> <getdate
Last updated: Fri, 09 May 2008

view this page in

gettimeofday

(PHP 4, PHP 5)

gettimeofday — 現在の時間を得る

説明

mixed gettimeofday ([ bool $return_float ] )

この関数は、gettimeofday(2) へのインターフェイスです。 この関数は、システムコールから返されたデータを有する連想配列を返します。

パラメータ

return_float

TRUE を指定すると、配列ではなく float で返します。

返り値

デフォルトでは配列を返します。return_float が設定されている場合は float を返します。

配列のキー:

  • "sec" - UNIX エポックからの秒
  • "usec" - マイクロ秒
  • "minuteswest" - グリニッジ基準の分
  • "dsttime" - 夏時間補正の型

変更履歴

バージョン 説明
5.1.0 return_float パラメータが追加されました。

例1 gettimeofday() の例

<?php
print_r
(gettimeofday());

echo 
gettimeofday(true);
?>

上の例の出力は、たとえば 以下のようになります。

Array
(
    [sec] => 1073504408
    [usec] => 238215
    [minuteswest] => 0
    [dsttime] => 1
)

1073504408.23910



gmdate> <getdate
Last updated: Fri, 09 May 2008
 
add a note add a note User Contributed Notes
gettimeofday
void0( the dog )yandex.ru
20-Sep-2006 11:07
do you realy think that convertion to String and back to float can be fast??
this function runs 10 times faster than utime() :

function fastUtime()
{
  $t = gettimeofday();
  return (float) ($t['sec'] + $t['usec'] / 1000000.0);
}
lucas dot karisny at linuxmail dot org
13-Feb-2005 06:26
A small improvement on getTimer.  Using vsprintf instead of sprintf there is no need to assign the array:

<?php
function utime()
{
  return (float) (
vsprintf('%d.%06d', gettimeofday()));
}
?>

In a test on my machine getTimer took 0.037519 seconds to run through 1000 iterations versus 0.027912 seconds for utime.  In total, utime runs about 25% quicker.  The use is negligible in an actual benchmarking scenario, but this could provide a slightly more accurate estimate.  Of course the time it takes to run the function could always be stored at the start and subtracted from your total value each time it is run.
middleto at pilot dot msu dot edu
12-Aug-1999 07:49
The types of DST correction (from sys/time.h on a Linux system):
 0     Not on DST
 1     USA DST
 2     Austrailian DST
 3     Western European DST
 4     Middle European DST
 5     Eastern European DST
 6     Canada DST
 7     Great Britain and Eire DST
 8     Rumania DST
 9     Turkey
10     Australian DST (with shift in 1986)

gmdate> <getdate
Last updated: Fri, 09 May 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites