Unix Timestamp in PHP

PHP's time() function returns the current Unix timestamp in seconds. For milliseconds, use microtime(). DateTime and Carbon are popular for date arithmetic.

Code Examples

Current timestamp (seconds)

time();

The simplest way. Returns the current Unix timestamp as an integer (seconds). Available in all PHP versions.

Current timestamp (milliseconds)

round(microtime(true) * 1000);

microtime(true) returns seconds as a float with microsecond precision. Multiply by 1000 and round for milliseconds.

Using DateTime class

$dt = new DateTime('now', new DateTimeZone('UTC'));
$timestamp = $dt->getTimestamp();

Object-oriented approach. Useful when you're already working with DateTime objects.

Convert timestamp to date string

date('Y-m-d H:i:s', $timestamp);

Format a Unix timestamp as a human-readable date. The second argument defaults to now if omitted.

Carbon (Laravel / popular library)

use Carbon\Carbon;
Carbon::now()->timestamp;

Carbon is the standard date library in the Laravel ecosystem. ->timestamp returns seconds since epoch.

Note

PHP's time() returns seconds, consistent with C and Unix conventions. Unlike JavaScript and Java, PHP does not default to milliseconds. The microtime() function provides sub-second precision when needed.

Frequently Asked Questions

How do I get the current Unix timestamp in PHP?

Use time(), which returns the current Unix timestamp as an integer — the number of seconds since January 1, 1970 UTC. It's available in all PHP versions and requires no imports.

What is the difference between time() and microtime() in PHP?

time() returns whole seconds as an integer. microtime(true) returns seconds as a float with microsecond precision (e.g., 1708560000.123456). Use time() for standard timestamps and microtime() when you need sub-second resolution, such as for performance benchmarking or generating millisecond timestamps.

How do I convert a Unix timestamp to a date string in PHP?

Use the date() function: date('Y-m-d H:i:s', $timestamp) returns a human-readable string. For timezone-aware formatting, create a DateTime object: new DateTime('@' . $timestamp) and use setTimezone() to convert to the desired timezone.

Does PHP's time() return UTC or local time?

time() always returns Unix time, which is UTC-based and timezone-agnostic. It's simply a count of seconds — there's no timezone embedded. The timezone only matters when you convert it to a human-readable string using date() or DateTime::format().

What is Carbon and when should I use it for timestamps in PHP?

Carbon is a popular PHP date library (the standard in Laravel). It wraps DateTime with an expressive API. Use Carbon::now()->timestamp for the current Unix timestamp, or Carbon::createFromTimestamp($ts) to create a Carbon instance from an existing timestamp. It's particularly useful for date arithmetic like addDays(), subHours(), and diffForHumans().

Main Epoch Converter

Use the homepage when you need epoch to date, date to epoch, or a full epoch converter

This PHP guide shows how to create and parse Unix timestamps in code. If your next step is broader search intent like epoch converter, epoch to date, epoch time to date, or unix epoch converter, jump back to the live homepage tools to paste a raw Unix value, auto-detect seconds versus milliseconds, and copy the readable answer instantly.

Related Tools

More free tools for developers debugging timestamps, schedules, and text changes.