CURRENT EPOCH · EPOCHTIME.TOOLS · A PRECISION INSTRUMENT FOR TIME
Converter Batch Difference Blog
Languages
JavaScript Python TypeScript Go Rust Java PHP SQL Bash
Specialty
LDAP Timestamp .NET Ticks Chrome/WebKit Cocoa / Core Data Discord Timestamp Excel OADate Unix Hex
Standards
ISO 8601 Guide Year 2038 NTP Timestamp GPS Time Julian Day

Get current Unix timestamp

PHP's `time()` returns epoch seconds. `microtime(true)` gives float seconds with sub-second precision.

Seconds

<?php
$now = time();
// → 1735689600

Milliseconds

<?php
$ms = (int) (microtime(true) * 1000);
// → 1735689600123

Float with precision

<?php
$t = microtime(true);
// → 1735689600.123456

Convert epoch to DateTime

Use `DateTime` (mutable) or `DateTimeImmutable` (preferred for new code).

Seconds → DateTime

<?php
$dt = (new DateTimeImmutable())->setTimestamp(1735689600);
echo $dt->format(DATE_ATOM);
// → 2025-01-01T00:00:00+00:00

In a specific timezone

<?php
$tz = new DateTimeZone('America/New_York');
$dt = (new DateTimeImmutable())->setTimestamp(1735689600)->setTimezone($tz);
echo $dt->format('Y-m-d H:i:s e');
// → 2024-12-31 19:00:00 America/New_York

Quick one-liner

<?php
echo date("Y-m-d H:i:s", 1735689600);  // local time
echo gmdate("Y-m-d H:i:s", 1735689600); // UTC

Convert DateTime to epoch

DateTime has `.getTimestamp()`. Or use `strtotime()` for quick string-to-epoch.

From a DateTime

<?php
$dt = new DateTimeImmutable("2025-01-01 00:00:00 UTC");
$ts = $dt->getTimestamp();
// → 1735689600

Using strtotime()

<?php
$ts = strtotime("2025-01-01 00:00:00 UTC");
// → 1735689600
$ts2 = strtotime("next Monday");
$ts3 = strtotime("+1 hour");

Format for display

Use `->format()` with PHP's format characters, or `DATE_ATOM` / `DATE_RFC2822` constants.

ISO 8601

<?php
echo (new DateTimeImmutable())->format(DATE_ATOM);
// → 2025-01-01T12:34:56+00:00

RFC 2822

<?php
echo (new DateTimeImmutable())->format(DATE_RFC2822);
// → Wed, 01 Jan 2025 12:34:56 +0000

Custom format

<?php
echo (new DateTimeImmutable())->format('Y-m-d H:i:s');

Parse common formats

Use `DateTimeImmutable::createFromFormat()` for known formats, or `new DateTimeImmutable($str)` for flexible parsing.

Flexible parsing

<?php
$dt = new DateTimeImmutable("2025-01-01T00:00:00Z");

Strict parsing

<?php
$dt = DateTimeImmutable::createFromFormat("Y-m-d H:i:s", "2025-01-01 12:00:00");
if ($dt === false) {
    // parsing failed
}

Common gotchas

PHP date pitfalls.

Prefer DateTimeImmutable

<?php
// DateTime is mutable — methods like ->modify() change the original.
// DateTimeImmutable returns a new instance, which is safer.
$a = new DateTimeImmutable('2025-01-01');
$b = $a->modify('+1 day');
// $a is still 2025-01-01, $b is 2025-01-02

date.timezone in php.ini

<?php
// PHP issues warnings if date.timezone is not set in php.ini.
// Either set it globally or call date_default_timezone_set() at runtime.
date_default_timezone_set("UTC");

strtotime quirks

<?php
// strtotime is flexible but unpredictable for ambiguous strings.
// Always test with your specific input format.
strtotime('01/02/2025'); // is this Jan 2 or Feb 1?

Use the converter

Need to quickly check what a specific timestamp converts to? Use the main converter — paste any value and get every format back.

Working with many timestamps at once? Try the batch converter — paste a list, get a CSV or JSON file back.