note 108613 added to function.date
| From: | Anon | Date: | Thu, 10 May 2012 20:24:50 +0000 |
| Subject: | note 108613 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187799@lists.php.net to get a copy of this message | ||
I needed to convet a duration timestamp into H:i:s but whenever I did it kept bringing 5 back as
01:00:05 (due to some DST stuff) so I made this function to replace date(). It has no optimisations
but hopefully someone might find it useful:
<?php
function get_time_string(){
$time = 3600+(60*32)+(50); // 01:32:50
$time_string = '';
$hours = (int)($time/(60*60));
if(strlen($hours) > 1){
$time_string = $hours.':';
}else{
$time_string = '0'.$hours.':';
}
$minutes = (int)(($time%(60*60))/(60));
if($minutes >= 1){
if(strlen($minutes) > 1){
$time_string .= $minutes.':';
}else{
$time_string .= '0'.$minutes.':';
}
$seconds = ($time%(60*60))%(60);
if(strlen($seconds) > 1){
$time_string .= $seconds;
}else{
$time_string .= '0'.$seconds;
}
}else{
if(strlen($time) > 1){
$time_string .= '00:'.$time;
}else{
$time_string .= '00:0'.$time;
}
}
return $time_string;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 109.154.101.133
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- https://master.php.net/note/edit/108613
Del: integrated -- https://master.php.net/note/delete/108613/integrated
Del: useless -- https://master.php.net/note/delete/108613/useless
Del: bad code -- https://master.php.net/note/delete/108613/bad+code
Del: spam -- https://master.php.net/note/delete/108613/spam
Del: non-english -- https://master.php.net/note/delete/108613/non-english
Del: in docs -- https://master.php.net/note/delete/108613/in+docs
Del: other reasons-- https://master.php.net/note/delete/108613
Reject -- https://master.php.net/note/reject/108613
Search -- https://master.php.net/manage/user-notes.php