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 = Monday , 25-September-2017 , 15:23:20 , 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()
1506353000

Break down time variables

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

Array ( [tm_sec] => 20 [tm_min] => 23 [tm_hour] => 8 [tm_mday] => 25 [tm_mon] => 8 [tm_year] => 117 [tm_wday] => 1 [tm_yday] => 267 [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
8