note 118242 deleted from function.date by peehaa
| From: | peehaa@php.net | Date: | Fri, 06 Jan 2017 15:58:10 +0000 |
| Subject: | note 118242 deleted from function.date by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208717@lists.php.net to get a copy of this message | ||
Note Submitter: tkachenko_ivan at bk dot ru
----
<?php
/**
* Convert a strftime format to a date format
*
* Unsupported strftime formats : %U, %W, %C, %g, %r, %R, %T, %X, %c, %D, %F, %x
* Unsupported date formats : S, n, t, L, B, G, u, e, I, P, Z, c, r
*
* @param string $strftimeFormat a strftime format
* @return string
*/
function strftimeFormatToDate($strftimeFormat) {
$caracs = array(
"%d" => "d",
"%a" => "D",
"%e" => "j",
"%A" => "l",
"%u" => "N",
"%w" => "w",
"%j" => "z",
"%V" => "W",
"%B" => "F",
"%m" => "m",
"%b" => "M",
"%G" => "o",
"%Y" => "Y",
"%y" => "y",
"%P" => "a",
"%p" => "A",
"%l" => "g",
"%I" => "h",
"%H" => "H",
"%M" => "i",
"%S" => "s",
"%z" => "O",
"%Z" => "T",
"%s" => "U",
);
return strtr((string)$strftimeFormat, $caracs);
}
$strftimeFormat = '%Y-%m-%d %H:%M:%S';
$formatDate = strftimeFormatToDate($strftimeFormat); // Y-m-d H:i:s
?>