#45: Getting the Current Timestamp

To get the current timestamp, call the time() function with no arguments. The return value is the current timestamp on the server. This simple example prints the current time:

echo 'The current timestamp is ' . time();

You can also assign the returned value of the timestamp() function to variables, like so:

$time = time();

Many PHP date-related functions take a timestamp argument, and most of them use the current time if you don't supply that parameter. For example, the date() function returns a formatted date string in a custom format (like Nov 1, 2006), by using the syntax date("format", timestamp). But if you don't give it a timestamp, the default is the current time. This means that for most of the time functions, ...

Get Wicked Cool PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.