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"); // CDT
UPDATE
how do I obtain current time on Greenwich? calculating with date("O")? is there other way?
The gmtime() function returns a pointer to a struct tm. Upon successful completion, gmtime_r() returns the address of the structure pointed to by the argument result. If an error is detected, or UTC is not available, gmtime_r() returns a NULL pointer.
In the C Programming Language, the gmtime function converts a calendar time (pointed to by timer) and returns a pointer to a structure containing a UTC (or Greenwich Mean Time) value.
The gmtime() function converts the calendar time timep to broken-down time representation, expressed in Coordinated Universal Time (UTC). It may return NULL when the year does not fit into an integer.
The mktime subroutine returns the specified time in seconds encoded as a value of type time_t. If the time cannot be represented, the function returns the value (time_t)-1. The localtime and gmtime subroutines return a pointer to the struct tm.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With