How to Get the Current Unix Time in PHP with time()
Unix time counts the seconds since 1 January 1970 UTC, and many systems store and exchange times that way. In PHP, time() returns it as a whole number, and gmdate() turns it into readable text in UTC.
Syntax
$<now> = time();
echo gmdate(<format>, $<now>);
| Part | What it does |
|---|---|
time() | The current Unix time, in whole seconds. |
gmdate(<format>, <timestamp>) | Formats a timestamp as text, in UTC. |
DATE_ATOM | A built-in format for ISO 8601 dates, such as 2026-11-26T07:38:08+00:00. |
The PHP manual for time(): "Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)." And for gmdate(): "Identical to the date() function except that the time returned is Greenwich Mean Time (GMT)."
The Example
The example prints the current Unix time and the same moment as a date and time in UTC.
Prerequisites
- PHP for the command line. This guide uses PHP 8.6.0.
Step 1: Write the Code
Create a file named main.php:

<?php
$now = time();
echo $now, "\n";
echo gmdate(DATE_ATOM, $now), "\n";
Step 2: Run It
php main.php
1795678688
2026-11-26T07:38:08+00:00

Your numbers will differ: they're the moment you run it. +00:00 shows the date is in UTC. The command is the same in zsh, bash and PowerShell.
Times in the Future
Because it's a plain number of seconds, adding time is arithmetic: time() + 15 * 60 is the Unix time 15 minutes from now.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Using date() and expecting UTC | date() uses the configured default time zone | Use gmdate() for UTC |
Treating time() as milliseconds | It's seconds; JavaScript's Date.now() is milliseconds | Multiply or divide by 1,000 when you exchange values |
Calling time() twice and expecting the same value | A second can pass between the calls | Call it once and reuse the result |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| A formatted time is hours off | date() used a local time zone | Switch to gmdate(), or set the time zone explicitly |
| A date far in the future | Milliseconds were treated as seconds | Divide by 1,000 |
FAQ
Do Unix timestamps contain a time zone?
No. The manual notes that "Unix timestamps do not contain any information with regards to any local timezone." The zone only matters when you format them.
How do I get fractions of a second?
microtime(true) returns the current Unix time as a float with microseconds.
Conclusion
time() returns the current Unix time in seconds, arithmetic moves it forward or back, and gmdate() formats it in UTC.
