Converting a Time Stamp with getdate():
The function
getdate() optionally accepts a time stamp and
returns an associative array containing information about the date. If
you omit the time stamp, it works with the current time stamp as
returned by time().
Following table lists the elements contained in the array returned by getdate().
Key | Description | Example |
seconds | Seconds past the minutes (0-59) | 20 |
minutes | Minutes past the hour (0 - 59) | 29 |
hours | Hours of the day (0 - 23) | 22 |
mday | Day of the month (1 - 31) | 11 |
wday | Day of the week (0 - 6) | 4 |
mon | Month of the year (1 - 12) | 7 |
year | Year (4 digits) | 1997 |
yday | Day of year ( 0 - 365 ) | 19 |
weekday | Day of the week | Thursday |
month | Month of the year | January |
0 | Timestamp | 948370048 |
Now you have complete control over date and time. You can format this date and time in whatever format you wan.
Example:
Try out following example
<?php
$date_array = getdate();
foreach ( $date_array as $key => $val )
{
print "$key = $val<br />";
}
$formated_date = "Today's date: ";
$formated_date .= $date_array[mday] . "/";
$formated_date .= $date_array[mon] . "/";
$formated_date .= $date_array[year];
print $formated_date;
?>
|
It will produce following result:
seconds = 27
minutes = 25
hours = 11
mday = 12
wday = 6
mon = 5
year = 2007
yday = 131
weekday = Saturday
month = May
0 = 1178994327
Today's date: 12/5/2007
No comments:
Post a Comment