Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

understanding gmtime return value

Tags:

timezone

php

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?

like image 366
Luis Siquot Avatar asked Jul 18 '11 17:07

Luis Siquot


People also ask

What does Gmtime return?

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.

How does gmtime work?

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.

Can Gmtime return null?

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.

What is the difference between Mktime () and Gmtime ()?

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.


1 Answers

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

like image 104
Naftali Avatar answered Sep 21 '22 14:09

Naftali