note 114532 added to function.strftime
| From: | eric dot brison at anakeen dot com | Date: | Tue, 04 Mar 2014 12:55:50 +0000 |
| Subject: | note 114532 added to function.strftime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-198783@lists.php.net to get a copy of this message | ||
strftime not format microsecond (decimal part of seconds).
This function add '%f' key in format to render microsecond (6 digits) also.
<?php
/**
* @param string $format strftime format
* @param float $microtime time with microsecond
* @return string
*/
function strftimeu($format, $microtime)
{
if (preg_match('/^[0-9]*\\.([0-9]+)$/', $microtime, $reg)) {
$decimal = substr(str_pad($reg[1], 6, "0"), 0, 6);
} else {
$decimal = "000000";
}
$format = preg_replace('/(%f)/', $decimal, $format);
return strftime($format, $microtime);
}
?>
Example :
<?php
$now=microtime(true);
printf("REF:%s\n",$now );
printf("FMT:%s\n", strftimeu('%H:%M:%S.%f', $now));
?>
Results are :
REF:1393937303.6615
FMT:13:48:23.661500
FMT:13h 48min 23s 661500µs
Note : Here the decimal part of microtime is on 4 digits due to default precision
----
Server IP: 195.221.21.36
Probable Submitter: 88.171.49.38
----
Manual Page -- http://php.net/manual/en/function.strftime.php
Edit -- https://master.php.net/note/edit/114532
Del: integrated -- https://master.php.net/note/delete/114532/integrated
Del: useless -- https://master.php.net/note/delete/114532/useless
Del: bad code -- https://master.php.net/note/delete/114532/bad+code
Del: spam -- https://master.php.net/note/delete/114532/spam
Del: non-english -- https://master.php.net/note/delete/114532/non-english
Del: in docs -- https://master.php.net/note/delete/114532/in+docs
Del: other reasons-- https://master.php.net/note/delete/114532
Reject -- https://master.php.net/note/reject/114532
Search -- https://master.php.net/manage/user-notes.php