Link to home
Start Free TrialLog in
Avatar of dmehran
dmehranFlag for United States of America

asked on

how to convert epoch time to human readable time

Hi,

I like to know if there is a function or method anyone would know in PHP that converts epoch time to human readable time.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Joe Wu
Joe Wu
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
More information on the date() function here:
http://www.php.net/date

basically you supply a string as the first argument, and your epoch time as your second argument.

To get the full deal something like this would display the time as well:

<?php
      echo date("Y-m-d H:i:s","1196559376");
?>

Hope this helps, to get more examples on what string you should use in the first argument, please refer to the site above.
Avatar of dmehran

ASKER

Oh my, I am not sure how this slipped under my radar! For whatever reason I was thinking of something way more complicated than passing couple of arguments to the date function.

Thanks
no problem glad to help! :)
Avatar of a2liter
a2liter

Here is a handy function that I use all the time, you cna just add formats to return to your hearts content. These are just the most common ones that I use.


function sec2date($ticks,$method = 1){
 if ($method == 1)
  $date= date("Y-m-d H:i:s", $ticks);
 else if ($method == 2)
  $date= date("m/d/y H:i:s", $ticks);
 return $date;
}

Open in new window