PHP timestamp is usually 10 digits, indicating the number of seconds that have passed from January 1, 1970 00:00:00 UTC to the current time. However, some systems may also use a 13-digit timestamp, indicating the number of milliseconds that have elapsed from January 1, 1970 00:00:00 UTC to the current time. Next I will give specific code examples to demonstrate how to use PHP to obtain timestamps with different digits.
Get the 10-digit timestamp:
// 获取当前时间的10位时间戳 $timestamp = time(); echo $timestamp;
Get the 13-digit timestamp:
// 获取当前时间的13位时间戳 $timestamp = microtime(true) * 1000; echo $timestamp;
In the above example, We used the time()
function and the microtime()
function to obtain the 10-digit and 13-digit timestamps respectively. The time()
function returns the current Unix timestamp, accurate to seconds, while the microtime(true)
function returns the current time in microseconds, converted to milliseconds by multiplying by 1000. Finally the timestamp is stored in a variable and output to the screen.
However, it should be noted that when processing 13-digit timestamps, data type conversion or further processing may be required. How to use timestamps will be determined based on business needs. Hopefully the above will help you better understand the number of digits in PHP timestamps.
The above is the detailed content of How many digits does a PHP timestamp usually have?. For more information, please follow other related articles on the PHP Chinese website!