gettimeofday
(PHP 4, PHP 5)
gettimeofday — Get current time
Description
This is an interface to gettimeofday(2). It returns an associative array containing the data returned from the system call.
Parameters
-
return_float
-
When set to
TRUE
, a float instead of an array is returned.
Return Values
By default an array is returned. If return_float
is set, then a float is returned.
Array keys:
- "sec" - seconds since the Unix Epoch
- "usec" - microseconds
- "minuteswest" - minutes west of Greenwich
- "dsttime" - type of dst correction
Changelog
Version | Description |
---|---|
5.1.0 |
The return_float parameter was added.
|
Examples
Example #1 gettimeofday() example
<?php
print_r(gettimeofday());
echo gettimeofday(true);
?>
The above example will output something similar to:
Array ( [sec] => 1073504408 [usec] => 238215 [minuteswest] => 0 [dsttime] => 1 ) 1073504408.23910
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с датой и временем
- Дата и Время
- checkdate
- date_add
- date_create_from_format
- date_create_immutable_from_format
- date_create_immutable
- date_create
- date_date_set
- date_default_timezone_get
- date_default_timezone_set
- date_diff
- date_format
- date_get_last_errors
- date_interval_create_from_date_string
- date_interval_format
- date_isodate_set
- date_modify
- date_offset_get
- date_parse_from_format
- date_parse
- date_sub
- date_sun_info
- date_sunrise
- date_sunset
- date_time_set
- date_timestamp_get
- date_timestamp_set
- date_timezone_get
- date_timezone_set
- date
- getdate
- gettimeofday
- gmdate
- gmmktime
- gmstrftime
- idate
- localtime
- microtime
- mktime
- strftime
- strptime
- strtotime
- time
- timezone_abbreviations_list
- timezone_identifiers_list
- timezone_location_get
- timezone_name_from_abbr
- timezone_name_get
- timezone_offset_get
- timezone_open
- timezone_transitions_get
- timezone_version_get
Коментарии
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)
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.