time

Return current Unix timestamp

Syntax

time ( void ) : int

Return

Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).

Examples

1

<?

$return = time();

echo $return;

?>
1639055100

2

<?

$return = time();

$second = 1;
$minute = $second * 60;
$hour = $minute * 60;
$day = $hour * 24;
$week = $day * 7;
$month = $day * 30;
$year = $day * 365;

$format = "Y-m-d H:i:s";

echo date($format, $return) . PHP_EOL;
echo date($format, $return + $second) . PHP_EOL;
echo date($format, $return + $minute) . PHP_EOL;
echo date($format, $return + $hour) . PHP_EOL;
echo date($format, $return + $day) . PHP_EOL;
echo date($format, $return + $week) . PHP_EOL;
echo date($format, $return + $month) . PHP_EOL;
echo date($format, $return + $year);

?>
2021-12-09 13:05:00
2021-12-09 13:05:01
2021-12-09 13:06:00
2021-12-09 14:05:00
2021-12-10 13:05:00
2021-12-16 13:05:00
2022-01-08 13:05:00
2022-12-09 13:05:00

3

<?

date_default_timezone_set("UTC");
echo time() . " UTC\n";

date_default_timezone_set("America/Los_Angeles");
echo time() . " America/Los_Angeles\n";

date_default_timezone_set("Europe/London");
echo time() . " Europe/London";

?>
1639055100 UTC
1639055100 America/Los_Angeles
1639055100 Europe/London

PHP

Home Menu