note 96424 added to function.strftime
| From: | baptiste dot place at utopiaweb dot fr | Date: | Fri, 26 Feb 2010 12:54:53 +0000 |
| Subject: | note 96424 added to function.strftime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-166394@lists.php.net to get a copy of this message | ||
Created this small method to convert a date format to a strftime format. One format is enough to
learn :)
/**
* Convert a date format to a strftime format
*
* Timezone conversion is done for unix. Windows users must exchange %z and %Z.
*
* Unsupported date formats : S, n, t, L, B, G, u, e, I, P, Z, c, r
* Unsupported strftime formats : %U, %W, %C, %g, %r, %R, %T, %X, %c, %D, %F, %x
*
* @param string $dateFormat a date format
* @return string
*/
public static function dateFormatToStrftime($dateFormat) {
$caracs = array(
// Day - no strf eq : S
'd' => '%d', 'D' => '%a', 'j' =>
'%e', 'l' => '%A', 'N' => '%u',
'w' => '%w', 'z' => '%j',
// Week - no date eq : %U, %W
'W' => '%V',
// Month - no strf eq : n, t
'F' => '%B', 'm' => '%m', 'M' =>
'%b',
// Year - no strf eq : L; no date eq : %C, %g
'o' => '%G', 'Y' => '%Y', 'y' =>
'%y',
// Time - no strf eq : B, G, u; no date eq : %r, %R, %T, %X
'a' => '%P', 'A' => '%p', 'g' =>
'%l', 'h' => '%I', 'H' => '%H',
'i' => '%M', 's' => '%S',
// Timezone - no strf eq : e, I, P, Z
'O' => '%z', 'T' => '%Z',
// Full Date / Time - no strf eq : c, r; no date eq : %c, %D, %F, %x
'U' => '%s'
);
return strtr((string)$dateFormat, $caracs);
}
I use it with this condition on a date format :
if(preg_match("/(D|l|F|M)/", $format))
----
Server IP: 195.221.21.36
Probable Submitter: 85.170.209.162
----
Manual Page -- http://www.php.net/manual/en/function.strftime.php
Edit -- https://master.php.net/note/edit/96424
Del: integrated -- https://master.php.net/note/delete/96424/integrated
Del: useless -- https://master.php.net/note/delete/96424/useless
Del: bad code -- https://master.php.net/note/delete/96424/bad+code
Del: spam -- https://master.php.net/note/delete/96424/spam
Del: non-english -- https://master.php.net/note/delete/96424/non-english
Del: in docs -- https://master.php.net/note/delete/96424/in+docs
Del: other reasons-- https://master.php.net/note/delete/96424
Reject -- https://master.php.net/note/reject/96424
Search -- https://master.php.net/manage/user-notes.php