rarebit Posted June 2, 2008 Share Posted June 2, 2008 Hi, I want to display how much time is left on things (e.g. poll), i've looked around php.net, but it seems like time and rather than subtracting the epoch away I did this... function time_split($secs) { // YEARS $years = intval($secs / 31536000); $rem = $secs % 31536000; // DAYS $days = intval($rem / 86400); $rem = $rem % 86400; // HOURS $hours = intval($rem / 3600); $rem = $rem % 3600; // MINS $mins = intval($rem / 60); $rem = $rem % 60; $sret = ""; if($years>0) { $s=""; if($years>1) { $s="s"; } $sret .= $years." year".$s." "; } if($days>0) { $s=""; if($days>1) { $s="s"; } $sret .= $days." day".$s." "; } if($hours>0) { $s=""; if($hours>1) { $s="s"; } $sret .= $hours." hour".$s." "; } if($mins>0) { $s=""; if($mins>1) { $s="s"; } $sret .= $mins." min".$s." "; } if($rem>0) { $s=""; if($rem>1) { $s="s"; } $sret .= $rem." sec".$s.""; } return $sret; } $n = 35190462; print time_split($n); is there a better way? (even by bit shifting or something?) ta Link to comment https://forums.phpfreaks.com/topic/108440-is-there-a-built-in-way/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.