1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Convert centiseconds timer to mm:ss:cc ?

Discussion in 'PHP' started by AKnogood, Mar 1, 2011.

  1. #1
    I would need a small php script to convert centiseconds to minutes, seconds and centiseconds using that format: mm:ss:cc.

    It's probably pretty easy to code but I'm not a good coder. :)
     
    AKnogood, Mar 1, 2011 IP
  2. tvoodoo

    tvoodoo Active Member

    Messages:
    239
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    53
    #2
    
    $centiseconds = 123456;
    $minutes = abs($centiseconds / 6000);
    $centiseconds = abs($centiseconds / 6000);
    $seconds = abs($centiseconds / 100);
    $centiseconds = abs($centiseconds / 100);
    echo sprintf("%02d:%02d:%02d",$minutes,$seconds,$centiseconds);
    
    PHP:
     
    tvoodoo, Mar 1, 2011 IP
  3. AKnogood

    AKnogood Active Member

    Messages:
    244
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Unfortunately this is not working...
     
    AKnogood, Mar 1, 2011 IP
  4. tvoodoo

    tvoodoo Active Member

    Messages:
    239
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    53
    #4
    
    <?php
        $centiseconds = 60830;
        $minutes = abs($centiseconds / 6000);
        $centiseconds = abs($centiseconds % 6000);
        $seconds = abs($centiseconds / 100);
        $centiseconds = abs($centiseconds % 100);
        echo sprintf("%02d:%02d:%02d",$minutes,$seconds,$centiseconds);
    ?>
    
    PHP:
     
    tvoodoo, Mar 1, 2011 IP
  5. AKnogood

    AKnogood Active Member

    Messages:
    244
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    60
    #5
    Are you sure that we need the abs (absolute) function?
    Don't we need the round function instead?
     
    AKnogood, Mar 1, 2011 IP
  6. tvoodoo

    tvoodoo Active Member

    Messages:
    239
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    53
    #6
    if you have 5.55 if you use abs it will give you 5 if you use round it will give you 6 , which is more than you actually have. So use which ever you want it doesn't matter to me.
     
    tvoodoo, Mar 1, 2011 IP
  7. AKnogood

    AKnogood Active Member

    Messages:
    244
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    60
    #7
    Ok, thanks for the script!
     
    AKnogood, Mar 2, 2011 IP