By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

PHP: Convert your unix timestamps to readable formats.

How to convert your unix timestamps to readable date and time formats.

Created: 2011-11-09 11:08

How to Convert unix timestamp to readable time formats using the script provided in this Article. For this we will be using the date function of PHP, and we'll be using the dd/mm/YYYY format.

echo date("d/m/Y", $timestamp);

Now, if you want to add the hours and seconds, we simply add another date function, and connect the output from the date function using a dot in between the two, this is called String Concatenation.

echo date("d/m/Y", $timestamp) .'At the:'.date("G:i", $timestamp);

Capital Y shows the full year. The m shows the numeric representation of a month, with leading zeros. The d shows the day, using 2 digits with leading zeros.

The capital G is used for 24 hour formats, and the small i represents seconds, while the ":" part is simply the separator.