Reputation: 2804
time() returns the current time measured in the number of seconds since the
Unix Epoch (January 1 1970 00:00:00 GMT).
My question is:
time();
from a server locating on UK is different from a server located on USA? Or the unix time is calculated on GMT?Upvotes: 2
Views: 192
Reputation: 146593
The Unix epoch is a fixed moment in time, not a local time, so the number of seconds since them is the same no matter where you are. Server time only affects if the server's clock is wrong :)
You shouldn't care about GMT offsets if the function you use to display dates is timezone aware and properly configured:
<?php
$now = time();
date_default_timezone_set('Europe/Madrid');
echo date('Y-m-d H:i:s O e', $now) . PHP_EOL;
date_default_timezone_set('America/Hermosillo');
echo date('Y-m-d H:i:s O e', $now) . PHP_EOL;
... prints:
2011-08-09 13:33:58 +0200 Europe/Madrid
2011-08-09 04:33:58 -0700 America/Hermosillo
Upvotes: 2
Reputation: 13517
As outlined at the start of the manual and in your question, the time returned is seconds since the Unix Epoch
in GMT.
It is not your local time, you need to modify timezone settings or modify the value returned from time()
to be your local time.
Upvotes: 1