note 27929 added to function.date
| From: | brain at blunkweb dot de | Date: | Wed, 25 Dec 2002 23:07:12 +0000 |
| Subject: | note 27929 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-41285@lists.php.net to get a copy of this message | ||
this function will convert any M-character in the format string
to the full name of the corresponding month as defined in array $month
function format_date($timestamp,$format) {
$month = array("Januar", "Februar", "März", "April",
"Mai", "Juni", "Juli", "August", "September",
"Oktober", "November", "Dezember");
preg_match_all("/[[:alpha:]]/",$format,$character);
for($i=0;$i<count($character[0]);$i++) {
if($character[0][$i] == 'M') {
$formatted = $month[date("n",$timestamp)-1];
}
else {
$formatted = date($character[0][$i],$timestamp);
}
$format = preg_replace("/".$character[0][$i]."/",$formatted,$format,1);
}
return($format);
}
example:
$timestamp = "1039786744";
echo format_date($timestamp,"d. M Y H:i:s");
output:
13. Dezember 2002 14:39:04
--
http://www.php.net/manual/en/function.date.php
http://master.php.net/manage/user-notes.php?action=edit+27929
http://master.php.net/manage/user-notes.php?action=delete+27929
http://master.php.net/manage/user-notes.php?action=reject+27929