What is the usage of the PHP timestamp function?
The PHP timestamp function is used to retrieve the timestamp of the current time or a specific date and time.
There are several common PHP timestamp functions that are frequently used.
- time(): Obtain the timestamp of the current time.
$timestamp = time();
echo $timestamp;
- strtotime(): Converts a string to a timestamp.
$timestamp = strtotime("2022-01-01 00:00:00");
echo $timestamp;
- mktime(): Obtain a timestamp based on a specified date and time.
$timestamp = mktime(0, 0, 0, 1, 1, 2022);
echo $timestamp;
- date(): Format a timestamp into the specified date and time format.
$timestamp = time();
$date = date("Y-m-d H:i:s", $timestamp);
echo $date;
The above are commonly used PHP timestamp functions and their usage, you can choose the appropriate function based on your specific needs.