In PHP, a timestamp is usually a 10-digit number that represents the number of seconds since January 1, 1970 00:00:00 GMT. You can get the current timestamp using PHP's built-in time() function.
<?php // Get the current timestamp $timestamp = time(); echo "Current timestamp: ".$timestamp; ?>
Running the code above will output the current timestamp, typically a 10-digit number. To convert the timestamp into a human-readable date and time format, you can use the date() function.
<?php // Get the current timestamp $timestamp = time(); // Convert timestamp to date and time format $date = date("Y-m-d H:i:s", $timestamp); echo "Current time: ".$date; ?>
Through these examples, we can clearly understand that a PHP timestamp usually has 10 digits, and we learn how to obtain the current timestamp and convert it into a date-time format. In PHP development, timestamps are essential for time-related operations such as logging, scheduled tasks, and time comparisons.