Convert timestamp to readable date/time in PHP

Problem: Convert timestamp to readable date/time in PHP
Solution: This can be achieved with the help of date() function, which is an inbuilt function in PHP can be used to format the timestamp given by time() function. This function returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
echo date('m/d/Y H:i:s', 1541843467);
?>

chevron_right


Output:



11/10/2018 09:51:07

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
echo date('m/d/Y H:i:s', time());
?>

chevron_right


Output:

Current Time in formatted form

Reference: http://php.net/manual/en/function.date.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.