Date and Time
To display current date/time, use:
echo date('F d, Y H:i:s');
The result will be something like:
August 08, 2008, 14:06:39
To display a certain date or time formatted in a certain way, use mktime()
and date(). It takes two arguments: the format that describes how to print
the date and the time stamp that represents the date you want to print.
<?php
$dataEntry = mktime(18,15,0,1,10,2001);
$x = date('F d, Y - g:i a',$dataEntry);
echo "$x"
?>
will produce:
January 10, 2001--6:15 p.m.
To deal with times in Greenwich Mean Time (GMT), you can use gmdate()
and gmmktime(). For example, for a machine in eastern daylight time, which
is four hours behind GMT:
<?php
$today = mktime(12,0,0,6,6,2001);
echo 'Here it is '.date('g:i:s a, F d, Y',$today);
echo '';
echo 'In GMT it is '.gmdate('g:i:s a, F d, Y',$today);
?>
will produce:
Here it is 12:00:00 pm, June 6, 2001
In GMT it is 4:00:00 pm, June 6, 2001
|