Unix Timestamp Converter in PHP — Code Examples
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
// 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 . "
";- 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.
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 JavaScript / Node.js
JavaScript's Date object works in milliseconds. Divide by 1000 for Unix seconds. Use Intl.DateTimeFormat or date-fns for formatting.
Unix Timestamp Converter in Python
Python's datetime module and time module both handle Unix timestamps. Use datetime.fromtimestamp() for local time and datetime.utcfromtimestamp() for UTC.
Unix Timestamp Converter in Go
Go's time package uses int64 for Unix timestamps. time.Unix() converts to a time.Time value; .Unix() on a time.Time returns the epoch seconds.
Unix Timestamp Converter in Java
Java 8+ introduced the java.time package. Use Instant for UTC timestamps and ZonedDateTime for timezone-aware conversion.
Unix Timestamp Converter in Ruby
Ruby's Time class works natively with Unix timestamps. Use Time.now.to_i for the current epoch and Time.at to convert back.
Unix Timestamp Converter in Rust
Rust's std::time::SystemTime provides the raw timestamp. The chrono crate adds human-readable formatting and timezone support.
Unix Timestamp Converter in C# / .NET
C# uses DateTimeOffset for timezone-aware timestamps. ToUnixTimeSeconds() and FromUnixTimeSeconds() handle Unix epoch conversion.