note 24364 modified in function.getdate by jmcastagnetto

From: Date: Wed, 14 Aug 2002 20:47:31 +0000
Subject: note 24364 modified in function.getdate by jmcastagnetto
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-35025@lists.php.net to get a copy of this message
[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"]; --was-- 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"]; http://www.php.net/manual/en/function.getdate.php

« previous php.notes (#35025) next »