time

(PHP 4, PHP 5, PHP 7, PHP 8)

time返回当前的 Unix 时间戳

说明

time(): int

返回自从 Unix 纪元(格林威治时间 1970 年 1 月 1 日 00:00:00)到当前时间的秒数。

注意:

Unix 时间戳不包含任何有关本地时区的信息。建议使用 DateTimeImmutable 类来处理日期和时间信息, 以避免 Unix 时间戳带来的陷阱。

参数

此函数没有参数。

返回值

返回当前时间戳。

范例

示例 #1 time() 例子

<?php
echo 'Now: '. time();
?>

以上例程的输出类似于:

Now: 1660338149

注释

小技巧

$_SERVER['REQUEST_TIME'] 中保存了发起该请求时刻的时间戳。

参见

add a note

User Contributed Notes 1 note

up
-13
r at rcse dot de
4 months ago
time() gives the timestamp of Greenwich Mean Time (GMT) which is defined as the official time for the whole earth. You get the local time by adding the time zone offset to this timestamp.
To Top