Jump to content

[PHP] formatsecs()


djthyrax
 Share

Recommended Posts

Converte uma quantidade de segundos numa string com semanas, dias, horas, minutos e seguntos.

Ex: echo formatsecs(3661); iria dar 1h 1m 1s

function formatsecs($secs){
$times=array(
	'w'=>3600*24*7,
	'd'=>3600*24,
	'h'=>3600,
	'm'=>60
);
$str='';
foreach($times as $name=>$time){
	if($secs>$time){
		$num=floor($secs/$time);
		$secs=$secs%$time;
		$str.="$num$name ";
	}
}
$str.=$secs.'s';
return trim($str);
}

Não peças ajuda por PM! A tua dúvida vai ter menos atenção do que se for postada na secção correcta do fórum!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.