PHP - Current Date/Time -- With Milliseconds!

Discussion in 'Programming & Software Development' started by ChEEkY ChiNo, Nov 20, 2005.

  1. ChEEkY ChiNo

    ChEEkY ChiNo Member

    Joined:
    Sep 8, 2002
    Messages:
    2,143
    Location:
    Campbelltown, NSW
    Hi Guys,

    Is anyone aware of a way to get the current date/time including Milliseconds?

    I need to get the date in the format of:
    Day-Month-Year Hours-Minutes-Seconds-Milliseconds

    Any help?

    EDIT: I'm actually after Milliseconds and not Microseconds..

    Thanks
     
    Last edited: Nov 20, 2005
  2. akashra

    akashra Member

    Joined:
    Apr 25, 2003
    Messages:
    3,910
    Location:
    Melbourne, AU
    Code:
    	function getmicrotime()
    	{
    		list($usec, $sec) = explode(" ",microtime()); 
    		return ((float)$usec + (float)$sec); 
    	} 
    
    	$PAGE['starttime'] = getmicrotime(); 
    
    php.net rocks.

    Edit: I should mention, if you can't figure out how to use strftime with %c and time(), for the non-microsecond time, then, uhh... well... nevermind :)
     
    Last edited: Nov 20, 2005
  3. OP
    OP
    ChEEkY ChiNo

    ChEEkY ChiNo Member

    Joined:
    Sep 8, 2002
    Messages:
    2,143
    Location:
    Campbelltown, NSW
    Yeha i checked all over php.net and tried that query but didnt notice it would help!

    I get 1132470321.0824

    So is the .0824 part microseconds? Or what?
     
  4. n000b

    n000b Member

    Joined:
    Jul 4, 2002
    Messages:
    2,489
    Location:
    Melbourne
    Yes it is.
     
  5. n000b

    n000b Member

    Joined:
    Jul 4, 2002
    Messages:
    2,489
    Location:
    Melbourne
    Actually no it's not, that part should be milliseconds shouldn't it?
     
  6. OP
    OP
    ChEEkY ChiNo

    ChEEkY ChiNo Member

    Joined:
    Sep 8, 2002
    Messages:
    2,143
    Location:
    Campbelltown, NSW
    Ok got me a little confused here so i got some things cleared up.

    What im after is to get the current time with Milliseconds. Not to get microseconds... I was under the impression that they were the same thing just like American English/Real English kinda thing...


    Sound better?

    Thanks
     
  7. OP
    OP
    ChEEkY ChiNo

    ChEEkY ChiNo Member

    Joined:
    Sep 8, 2002
    Messages:
    2,143
    Location:
    Campbelltown, NSW
    Ok had a p[lay around, does this look about right?


     
    Last edited: Nov 20, 2005
  8. Buzzard

    Buzzard Member

    Joined:
    Apr 10, 2002
    Messages:
    758
    Location:
    Dandenong
    PHP:
    <?php

    function timeAndMilliseconds()
    {
        
    $m explode(' ',microtime());
        return array(
    $m[1], (int)round($m[0]*1000,3));


    list(
    $totalSeconds$extraMilliseconds) = timeAndMilliseconds();
    echo 
    date("d-m-Y H:i:s"$totalSeconds) . ".$extraMilliseconds\n";
    echo 
    date("d-m-Y H:i:s") . "\n";

    ?>
    EDIT: Removed prev post, this one does what you actually want :)
     
    Last edited: Nov 20, 2005
  9. akashra

    akashra Member

    Joined:
    Apr 25, 2003
    Messages:
    3,910
    Location:
    Melbourne, AU
    milliseconds is just going to be microseconds / 1000.
     
  10. OP
    OP
    ChEEkY ChiNo

    ChEEkY ChiNo Member

    Joined:
    Sep 8, 2002
    Messages:
    2,143
    Location:
    Campbelltown, NSW
    Thanks Buzzard, that looks fine :)

    :thumbup:
     

Share This Page

Advertisement: