在PHP中,可以使用strtotime()
函数将日期字符串转换为时间戳。例如:
$date_string = "2021-08-31"; $timestamp = strtotime($date_string); echo $timestamp; // 输出:1630473600
如果需要将时间戳转换为日期字符串,可以使用date()
函数。例如:
$timestamp = 1630473600; $date_string = date("Y-m-d", $timestamp); echo $date_string; // 输出:2021-08-31