PHP Display date and time

In this tutorial you will learn how to display the time in PHP program.

PHP displaying the time and date into your timezone

     

For a lot of people, when they use the date() function in PHP, it doesn't display the correct time and date for their region, as their servers may be in a different part of the world to where they are. This simple bit of code uses the gmdate() function to overcome this little problem.

General description of gmdate() function is as follows:

General Format string gmdate(string $format [, int $timestamp] )
Parameters $format: the format of the date string $timestamp: Integer Unix timestamp
Return Value Returns the formatted date string

Example 1:

<?php

ECHO "<b>Date using date()fucntion is:</b>"."<br/>";

echo date("M d Y H:i:s",mktime(0,0,0,1,1,1998))."<br/>";

ECHO "<b>Date using gmdate()fucntion is:</b>"."<br/>";

echo gmdate("M d Y H:i:s",mktime(0,0,0,1,1,1998))."<br/>";

?>

Output:

Date using date()fucntion is:
Jan 01 1998 00:00:00
Date using gmdate()fucntion is:
Jan 01 1998 00:00:00

Note: To know the date format in details please visit our web page: http://www.roseindia.net/tutorial/php/phpdate/index.html