CakeFest 2024: The Official CakePHP Conference

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

There are no user contributed notes for this page.
To Top