SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    534
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question convert time to unix

    Hi guys,

    I am trying to convert a time to a unix time stamp my code below: is producing incorrect results:



    PHP Code:
    <?php

    $x 
    =  ("03:14:59:20");
    $y =  ("01:16:01:02");
    echo 
    "Fist time:".$x."<$xbr/><br/>";
    echo 
    "Second time:".$y."<br/><br/>";
    $now explode(":",$x);      // gives us $now[0]=>2005, $now[1]=>11, $now[2] => 20
    $now2 explode(":",$y);      // gives us $now[0]=>2005, $now[1]=>11, $now[2] => 20
    $now mktime(0,0,0,$now[1],$now[2],$now[0]);   // make unix timestamp -must be month day year (www.php.net)
    $now2 mktime(0,0,0,$now[1],$now[2],$now[0]);   // make unix timestamp -must be month day year (www.php.net)
    $now3 $now $now2;
    echo 
    $now."   minus   ".$now2." equals:  ".$now3."<br/>"
    $date_array getdate($now3);
    echo 
    "The time is:".$date_array['hours'].":".$date_array['minutes'].":".$date_array['seconds'];
    ?>
    Can anyone suggest a correct and more efficient way of doing this.
    "Persistence is the path to perfection"

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2005
    Location
    Winnipeg
    Posts
    498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The only constant in software is change itself

  3. #3
    SitePoint Evangelist silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    534
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi thanks but I don't know how to use this for frames as in;

    20:34:12:23

    It doesn't specify a parameter to pass for this
    "Persistence is the path to perfection"

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Where are year, month, day coming from?

    You declare this:
    PHP Code:
    $x =  ("03:14:59:20"); 
    and then reference it here;
    PHP Code:
    $now explode(":",$x);      // gives us $now[0]=>2005, $now[1]=>11, $now[2] => 20 
    Which I cannot follow...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •