PHP time() Function
Quick summary: The PHP time() function returns the current Unix timestamp.
PHP time() Syntax
time(): int
PHP
PHP time() Basic examples
var_dump(time());
PHP
Output:
int(1707398400)
Returns seconds since Unix epoch.
PHP time() Real-world usage
$start = time();
sleep(1);
echo time() - $start;
PHP
Output:
1
Measures elapsed time in seconds.
PHP time() Edge cases
var_dump(time() > 0);
PHP
Output:
bool(true)
time() always returns a positive integer.
PHP time() Common mistakes
Using time for high-precision measurements
time() has second precision.
Incorrect
time();
Correct
microtime(true);
Use microtime for higher precision.
PHP time() Frequently Asked Questions
What does time() return?
Current Unix timestamp.
Use case of time()?
Timestamps for logs or sessions.
Timezone dependent?
No, always UTC.
Precision?
Seconds.
Alternative?
microtime().
Common mistake?
Expecting milliseconds.
Performance?
Very fast.
Used in sessions?
Yes.
Safe?
Yes.
Returns int?
Yes.
Best practice?
Store as integer.
Works cross-platform?
Yes.