Convert Unix timestamp to Date

 

Version Française | English Version

Unix Timestamp

Unix timestamp, also known as Unix time, POSIX time or Epoch is a representation of a date by the number of seconds since the January, the 1st of 1970 at midnight. Timestamp time is always UTC (Coordinated Universal Time) and is identical on all systems, whatever the timezone they are.

By example, the timestamp 1 is the 01/01/1970 at 00h00m01 UTC and timestamp 1713542348 is the 04/19/2024 à 15:59:08 UTC (format mm/dd/YYYY).

Convert easily dates to timestamps and timestamps to dates using the online timestamp converter below.

Epoch Timestamp UTC Date and time

: :       / /

Manipulate timestamps with PHP

With PHP, current timestamp is obtained with method time() or date() :

<?php 
echo time();
// or
echo date('U');
// gives 1392206400
?>

To display a timestamp in a date format we use method date() passing as second argument the timestamp to display:

<?php 
$exampleTimestamp = 1392206400;
echo date('d/m/Y H:i:s', $exampleTimestamp);
// gives 12/02/2014 12:00:00
?>

It's easy to add or substract a duration to a timestamp as it's only an ammount of seconds

<?php 
// Add 15 days to the date of 02/20/2014 at 15:30:00
$myDate = mktime(15, 30, 00, 02, 20, 2014) + (86400 * 15) ; // Note: there is 86400 seconds in a day
echo date('d/m/Y H:i:s', $myDate);
//  --> gives 07/03/2014 15:30:00



// Substract 3 hours 45 minutes to current date and time
// It's 19/04/2024 17:59:08
$myDate = date('U') - (3 * 3600 + 45 * 60); // Note: there is 3600 seconds in an hour
echo date('d/m/Y H:i:s', $myDate);
//  --> gives 19/04/2024 14:14:08
?>

↑ Haut de page

Norton Safe Web de Symantec .

Loïc LE MÉTAYER, depuis 2006
Me contacter