Learning PHP Home

Date & Time functions | PHP

Simple Output

Here is an example of out puting the day, date, time, timezone

echo date( 'l , d-F-Y , H:i:s , e , T' );
Example = Saturday , 18-November-2017 , 23:09:50 , Etc/Zulu , UTC

Time Zones

Find or set the timezone for your website.

echo date_default_timezone_get();
Example = Etc/Zulu


Here we are setting the server time zone than using the same code as above to output it.

echo date_default_timezone_set( 'America/Phoenix' );
Example = America/Phoenix

Time

The Time is out put in seconds.

echo time()
1511046590

Break down time variables

echo '<pre>'; print_r( localtime( time() , true ) ); echo '</pre>';

Array ( [tm_sec] => 50 [tm_min] => 9 [tm_hour] => 16 [tm_mday] => 18 [tm_mon] => 10 [tm_year] => 117 [tm_wday] => 6 [tm_yday] => 321 [tm_isdst] => 0 )

[tm_sec] - seconds
[tm_min] - minutes
[tm_hour] - hour
[tm_mday] - day of the month
[tm_mon] - month of the year (January=0)
[tm_year] - Years since 1900
[tm_wday] - Day of the week (Sunday=0)
[tm_yday] - Day of the year
[tm_isdst] - Is daylight savings time in effect
10