在PHP中,您可以使用time()函数来获取当前时间戳。这个函数返回自1970年1月1日00:00:00(UNIX纪元)以来的秒数。
示例代码:
<?php // 获取当前时间戳 $timestamp = time(); // 输出时间戳 echo "当前时间戳是:" . $timestamp; ?> 如果您需要获取特定日期和时间的时间戳,可以使用strtotime()函数。这个函数将任何英文文本的日期时间描述解析为UNIX时间戳。
示例代码:
<?php // 获取特定日期和时间的时间戳 $date_string = "2022-01-01 12:00:00"; $timestamp = strtotime($date_string); // 输出时间戳 echo "指定日期和时间的时间戳是:" . $timestamp; ?>