DevToolsForYou

Unix Timestamp Converter in PHP — Code Examples

Unix Timestamp Converter in PHPUse the online tool →

A Unix timestamp is the number of seconds (or milliseconds) since 1 January 1970 00:00:00 UTC. Here is how to get the current timestamp, convert to a human-readable date, and parse date strings back to timestamps in each language.

PHP's time() returns the current Unix timestamp. Use date() or DateTime for formatting and strtotime() for parsing.

PHP
<?php

// Current timestamp
$now = time(); // seconds since epoch
echo $now . "
";

// Timestamp → formatted date
echo date("Y-m-d H:i:s", 1700000000) . "
"; // uses server timezone
echo gmdate("Y-m-d H:i:s", 1700000000) . "
"; // always UTC

// Timestamp → DateTime (timezone-aware)
$dt = new DateTime("@1700000000"); // @ prefix = Unix timestamp
$dt->setTimezone(new DateTimeZone("Asia/Kolkata"));
echo $dt->format("Y-m-d H:i:s T") . "
"; // 2023-11-15 03:43:20 IST

// String → timestamp
$ts = strtotime("2023-11-14T22:13:20Z");
echo $ts . "
"; // 1700000000

// DateTime → timestamp
$ts2 = (new DateTime("2023-11-14T22:13:20Z"))->getTimestamp();
echo $ts2 . "
";
Notes & gotchas
  • date() uses the server timezone set in php.ini; gmdate() always uses UTC.
  • new DateTime('@timestamp') creates a UTC DateTime from a Unix timestamp.
  • strtotime() is flexible but ambiguous for formats like m/d/Y vs d/m/Y — use DateTime::createFromFormat() for reliable parsing.
Try it in your browser

Need to epoch/unix converter without writing code? The Unix Timestamp Converter runs entirely in your browser — paste your input and get the result instantly. No signup, no install, no data sent to a server.

Open Epoch/Unix Converter
Unix Timestamp Converter in other languages