note 24364 deleted from function.getdate by irchtml
| From: | irchtml@php.net | Date: | Wed, 25 Feb 2004 14:22:23 +0000 |
| Subject: | note 24364 deleted from function.getdate by irchtml | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-65721@lists.php.net to get a copy of this message | ||
Note Submitter:
----
[Editor's note: similar and more flexible formatting can be accomplished by using the date()
function, with or without use of time() or mk_time().]
The following code will "zero-fill" the code, convert to a 12 hour time and add am/pm
support.
// get current date
$current = getdate();
// format
$current["hours"] = $current["hours"] + 1;
if ($current["hours"] < 13) {
$ampm = " AM";
}
else {
$current["hours"] = $current["hours"] - 12;
$ampm = " PM";
}
if ($current["hours"] < 10) {
$current["hours"] = "0" . $current["hours"];
}
if ($current["minutes"] < 10) {
$current["minutes"] = "0" . $current["minutes"];
}
if ($current["seconds"] < 10) {
$current["seconds"] = "0" . $current["seconds"];
}
if ($current["mday"] < 10) {
$current["mday"] = "0" . $current["mday"];
}
// turn it into strings
$current_time = $current["hours"] . ":" . $current["minutes"] .
":" . $current "seconds"] . $ampm;
$current_date = $current["month"] . " " . $current["mday"] .
"," . " " . $current["year"];