note 83246 added to function.time
| From: | south dot minds at gmail dot com | Date: | Fri, 16 May 2008 15:09:04 +0000 |
| Subject: | note 83246 added to function.time | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-139447@lists.php.net to get a copy of this message | ||
Format seconds (if less or equal to 86400) into hours, minutes and seconds ± 1 sec. Change $time
and $myLocale to whatever your want and test from CLI (bash - linux) with
t=''; for i in $(seq 1 20); do t=$t"\n"$(php -f seconds2time.php) ; done ; echo
-e "$t" | sort -n
<?php
$time = mt_rand(0,86400);
$myLocale = "es_AR";
setlocale(LC_ALL,$myLocale);
$localeconv = localeconv();
$dec_point =$localeconv['decimal_point'];
($time > 86400) ? die("Time must be less than 86400 seconds") : '';
if($time % 3600 == 0){
$t_h[0] = $time/3600;
$t_m[0] = 0;
$t_s[0] = 0;
}else if ($time >= 3600 && ($time % 60) == 0 ){
$t_h = explode($dec_point,$time / 3600);
$t_m = explode($dec_point,('0.'.$t_h[1]) * 3600 / 60);
$t_s[0] = 0;
}else if($time < 3600 && ($time % 60) == 0 ){
$t_h[0] = 0;
$t_m = explode($dec_point,$time/ 60);
$t_s[0] = 0;
}else{
$t_h = explode($dec_point,$time / 3600);
$t_m = explode($dec_point,('0.'.$t_h[1]) * 3600 / 60);
$t_s[0] = ceil(('0.'.$t_m[1]) * 60);
}
print sprintf('%05d',$time) .' = ' . sprintf('%02d',$t_h[0]). '
hs. '. sprintf('%02d',$t_m[0]) . ' min. '
.sprintf('%02d',$t_s[0]) ." seg. \n";
?>
----
Server IP: 201.216.232.3
Probable Submitter: 200.59.194.34
----
Manual Page -- http://www.php.net/manual/en/function.time.php
Edit -- https://master.php.net/note/edit/83246
Del: integrated -- https://master.php.net/note/delete/83246/integrated
Del: useless -- https://master.php.net/note/delete/83246/useless
Del: bad code -- https://master.php.net/note/delete/83246/bad+code
Del: spam -- https://master.php.net/note/delete/83246/spam
Del: non-english -- https://master.php.net/note/delete/83246/non-english
Del: in docs -- https://master.php.net/note/delete/83246/in+docs
Del: other reasons-- https://master.php.net/note/delete/83246
Reject -- https://master.php.net/note/reject/83246
Search -- https://master.php.net/manage/user-notes.php