在PHP中,可以使用strtotime()
函数将日期字符串转换为时间戳。这是一个简单的示例:
<?php
// 日期字符串
$date_string = "2021-09-01";
// 使用strtotime()函数将日期字符串转换为时间戳
$timestamp = strtotime($date_string);
// 输出结果
echo "时间戳: " . $timestamp; // 结果:1630483200
?>
如果你需要将时间戳转换为日期字符串,可以使用date()
函数。例如:
<?php
// 时间戳
$timestamp = 1630483200;
// 使用date()函数将时间戳转换为日期字符串
$date_string = date("Y-m-d", $timestamp);
// 输出结果
echo "日期字符串: " . $date_string; // 结果:2021-09-01
?>
希望这对你有帮助!如果你有其他问题,请随时提问。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:php转时间戳怎样转换