Jump to content

Need to convert a timestamp into seconds only


Monkuar

Recommended Posts

 

Ok Let's say I have a timestamp:

 

1327482941

 

 

I want to convert this to output only "60"

 

im not looking for a whole time_ago function, simply just need to convert a timestamp down to seconds ONLY not having minutes/years/etc no need none of that just purely seconds starting from 1-60

 

if so how is it possible?

 

I tried to just

 

$seconds = substr($e,1,4) . "";

 

$e is my timestamp, I did this because I could just grab the last 2 digits in the timestamp that would be what I want, but that's not possible because it goes 1-90 not 1-60

 

^_^ help :D

 

 

 

Here is a code I am trying to make it only spit out 1-60 in seconds

 

function  timeAgo4($timestamp, $granularity=1){
        $difference = $timestamp;
        if($difference < 0) return '0';
        elseif($difference < 86400){
                   $periods = array(60,'' => 1);
                $output = '';
                foreach($periods as $key => $value){
                        if($difference >= $value){
                                $time = round($difference / $value);
                                $difference %= $value;
                                $output .= ($output ? ' ' : '').$time.' ';
                                
                                $granularity--;
                        }
                        if($granularity == 0) break;
                }
                return ($output ? $output : '0').'';
        }
        else return date($format, $timestamp);
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.