Menu Home

time

osbo.com | PHP | Functions | 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;

?>
1618538610

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-04-16 02:03:30
2021-04-16 02:03:31
2021-04-16 02:04:30
2021-04-16 03:03:30
2021-04-17 02:03:30
2021-04-23 02:03:30
2021-05-16 02:03:30
2022-04-16 02:03:30

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";

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

PHP