|
Tutorial 4
Date/Time Functions
- Functions demonstrated
-
- <?date($format,$time)>
<?gmdate($format,$time)>
<?time()>
The date() function is used to display times and dates in various ways. The
function takes a format string and a time as arguments. If the time argument is left off,
the current time and date will be used. The time argument is specified as an integer in
number of seconds since the Unix Epoch on Jan.1 1970. The format string is used to
indicate which date/time components should be displayed and how they should be formatted.
For example, if we wanted to print the current date and time, we might use a tag like:
<?echo
date("D M d, Y H:i:s")>. This looks like: Tue Oct 08, 1996 13:10:47
In the above you will find that the various characters in the formatting string were
replaced with a date/time component. Any characters not replaced with anything were
displayed verbosely. The valid formatting characters are:
- Y - Year eg. 1996
- y - Year eg. 96
- M - Month eg. Oct
- m - Month eg. 10
- D - Day eg. Tue
- d - Day eg. 08
- z - Day of the year eg. 281
- H - Hours in 24 hour format eg. 13
- h - Hours in 12 hour format eg. 01
- i - Minutes eg. 10
- s - Seconds eg. 47
- U - Seconds since epoch eg. 844794647
The gmdate() function is identical to the date() function except for the
fact that it uses Greenwich Mean Time instead of the current local time.
The time() function simply returns the current local time in seconds since Unix
epoch. It is equivalent to calling date("U").
|