understanding gmtime return value
I can't understand why gmdate()
and date()
reutrn the same values if my server is not configured to be on Greenwich Mean Time.
Why is this?
echo time(); // 1311011114
echo date("U"); // 1311011114
echo gmdate("U"); // 1311011114
echo date("j-m-y H:m:s"); // 18-07-11 12:07:14
echo date("e"); // America/Chicago
echo date("O"); // -0500
echo date("T"); 开发者_JS百科 // CDT
UPDATE
how do I obtain current time on Greenwich? calculating with date("O")? is there other way?Because time never changes -- it is always seconds since epoch (GMT).
Time is always the same. It is just your time-zone is different and that is how display date differs.
You can change your timezone in order to see time in the different zones.
See here for all the Date/Time functions
So a long time ago, people needed a way to determine time across multiple computing systems that was uniformed. The Computing Syndicate Council of Wise Elders (CSCWE for short) of the pre-Internet age were the ones that decided upon this. A secret ballot decided the arbitrary beginning point would be 1970 to herald a more advance computing age. So from that moment onwards, an unending march of seconds through the decades began, a new time for computing revolution with the steady beat of the seconds.
From this arbitrarily defined beginning, all computing time can be determined by running mathematical wizardry against this ever increasing number of seconds and then factoring in the timezones.
It is already answered but if you want to get local time and UTC time;
date_default_timezone_set('America/Chicago');
$format = 'Y-m-d H:i:s';
$time1 = time();
$time2 = strtotime(gmdate($format));
print date($format, $time1);
print date($format, $time2);
// 2014-07-24 17:31:23
// 2014-07-24 22:31:23
精彩评论