note 111998 added to function.strftime
| From: | Uwe at Familie-Loyal dot de | Date: | Sat, 20 Apr 2013 07:02:43 +0000 |
| Subject: | note 111998 added to function.strftime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194574@lists.php.net to get a copy of this message | ||
more fixed Problems while uing strftime in win32-systems.
function strftime_win32($format, $ts = null) {
if (!$ts) $ts = time();
$mapping = array(
'%C' => sprintf("%02d", date("Y",
$ts) / 100),
'%D' => '%m/%d/%y',
'%e' => sprintf("%' 2d",
date("j", $ts)),
'%h' => '%b',
'%n' => "\n",
'%r' => date("h:i:s", $ts) . " %p",
'%R' => date("H:i", $ts),
'%t' => "\t",
'%T' => '%H:%M:%S',
'%u' => ($w = date("w", $ts)) ? $w : 7
);
$format = str_replace(
array_keys($mapping),
array_values($mapping),
$format
);
if($format=='%V' or $format=='%G' or $format=='%g'){
// When strftime("%V") fails, some unoptimized workaround
//
// http://en.wikipedia.org/wiki/ISO_8601 : week 1 is
"the week with the year's first Thursday in it (the formal ISO definition)"
$year = strftime("%Y", $ts);
$isoyear=$year;
$first_day = strftime("%w", mktime(0, 0, 0, 1, 1, $year));
$last_day = strftime("%w", mktime(0, 0, 0, 12, 31, $year));
$number = $isonumber = strftime("%W", $ts);
// According to strftime("%W"), 1st of january is in week 1 if and
only if it is a monday
if ($first_day == 1) {
$isonumber--;
}
// 1st of january is between monday and thursday; starting (now) at 0 when
it should be 1
if ($first_day >= 1 && $first_day <= 4){
$isonumber++;
$isoyear=$year;
}elseif ($number == 0){
$isonumber = mktime(0, 0, 0, 12, 31, $year - 1);
$isoyear=$year;
}
if ($isonumber == 53 && ($last_day == 1 || $last_day == 2 ||
$last_day == 3)){
$isonumber = 1;
$isoyear=$year+1;
}
if ($format=='%V') {
return sprintf("%02d", $isonumber);
}elseif ($format=='%G'){
return sprintf("%04d", $isoyear);
}elseif ($format=='%g'){
return substr(sprintf("%04d", $isoyear),-2);
}
}else{
return strftime($format, $ts);
}
}
----
Server IP: 69.147.83.199
Probable Submitter: 87.155.121.115
----
Manual Page -- http://php.net/manual/en/function.strftime.php
Edit -- https://master.php.net/note/edit/111998
Del: integrated -- https://master.php.net/note/delete/111998/integrated
Del: useless -- https://master.php.net/note/delete/111998/useless
Del: bad code -- https://master.php.net/note/delete/111998/bad+code
Del: spam -- https://master.php.net/note/delete/111998/spam
Del: non-english -- https://master.php.net/note/delete/111998/non-english
Del: in docs -- https://master.php.net/note/delete/111998/in+docs
Del: other reasons-- https://master.php.net/note/delete/111998
Reject -- https://master.php.net/note/reject/111998
Search -- https://master.php.net/manage/user-notes.php