在PHP中,可以使用strtotime()
函数将日期字符串转换为时间戳。这是一个简单的示例:
<?php
// 日期字符串
$date_string = "2021-06-01";
// 使用strtotime()函数将日期字符串转换为时间戳
$timestamp = strtotime($date_string);
// 输出结果
echo $timestamp; // 结果为:1622438400
?>
如果你需要将当前日期和时间转换为时间戳,可以直接使用time()
函数:
<?php
// 获取当前日期和时间的时间戳
$current_timestamp = time();
// 输出结果
echo $current_timestamp; // 结果为当前日期和时间的时间戳
?>
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:php转时间戳如何转换