Unix Timestamps and date()
Get current time as a Unix timestamp and format it with date().
Time in PHP
PHP represents time as a Unix timestamp — the number of seconds since January 1, 1970, 00:00:00 UTC (the Unix epoch). Key functions:
time()— current Unix timestampdate($format, $timestamp)— format a timestampmktime()— create a timestamp from date parts
time()
Get the current Unix timestamp:
<?php
$now = time();
echo $now; // e.g. 1716800000
echo gettype($now); // integer
// 1 day in seconds
$tomorrow = time() + 86400;
$yesterday = time() - 86400;
echo date('Y-m-d', $tomorrow); // tomorrow's dateAll lessons in this course
- Unix Timestamps and date()
- The DateTime Class
- Date Arithmetic with DateInterval
- Timezones in PHP