Convert Linux/Unix timestamp to human readable format in PHP

This functin will help to convert the Linux/Unix timestamp to human readable format:

function unix_timestamp_to_human ($timestamp = "", $format = 'D d M Y - H:i:s')
{
    if (empty($timestamp) || ! is_numeric($timestamp)) $timestamp = time();
    return ($timestamp) ? date($format, $timestamp) : date($format, $timestamp);
}

$unix_time = "1251208071";

echo unix_timestamp_to_human($unix_time); //Return: Tue 25 Aug 2009 - 14:47:51
Share this
Anonymous's picture

ممنون دوست عزیز

به موقع به دردم خورد و سریع به کار بردم. تشکر
Anonymous's picture

Thank you

This saved me some time as I wouldn't have thought to use php's date. This is a very simple, elegant solution, so thank you for sharing.
Anonymous's picture

Thanks

It helped me a lot. Thank you.