note 108613 deleted from function.date by peehaa

From: Date: Fri, 06 Jan 2017 15:55:27 +0000
Subject: note 108613 deleted from function.date by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-208705@lists.php.net to get a copy of this message
Note Submitter: Anon ---- 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; } ?>

« previous php.notes (#208705) next »