Date/Time Functions Demo
- 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:
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.
- y - Year eg.
- M - Month eg.
- m - Month eg.
- D - Day eg.
- d - Day eg.
- z - Day of the year eg.
- H - Hours in 24 hour format eg.
- h - Hours in 12 hour format eg.
- i - Minutes eg.
- s - Seconds eg.
- U - Seconds since epoch eg.
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").