function time_str($ptime) {
	if($ptime>time()) {
		$etime = $ptime-time();
	} else {
    	$etime = time() - $ptime;
    }

    if ($etime < 1)
    {
        return '0 segundo';
    }

    $a = array( 12 * 30 * 24 * 60 * 60  =>  'ano',
                30 * 24 * 60 * 60       =>  'mese',
                24 * 60 * 60            =>  'dia',
                60 * 60                 =>  'hora',
                60                      =>  'minuto',
                1                       =>  'segundo'
                );
    if($ptime>time()) {
		foreach ($a as $secs => $str) {
	        $d = $etime / $secs;
	        if ($d >= 1)
	        {
	            $r = round($d);
	            return $r . ' ' . $str . ($r > 1 ? 's' : null) . ' restantes';
	        }
	    }
    } else {
	    foreach ($a as $secs => $str) {
	        $d = $etime / $secs;
	        if ($d >= 1)
	        {
	            $r = round($d);
	            return $r . ' ' . $str . ($r > 1 ? 's' : null) . ' atrĂ¡s';
	        }
	    }
	}
}