How can you convert the data type of a date in PHP?
In PHP, the date() function can be used to manipulate date data types. The syntax of this function is as follows:
date(string $format, int $timestamp = time())
The $format parameter is required to specify the format of the date, while the $timestamp parameter is optional and used to specify the timestamp of the date. Here are some common examples of date formats:
// 将时间戳转换为指定格式的日期
$timestamp = time();
$date = date('Y-m-d H:i:s', $timestamp);
// 将字符串转换为时间戳
$dateString = '2022-01-01';
$timestamp = strtotime($dateString);