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);
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.