PHP 日期时间:转换为 UNIX 时间戳 1 个改进

将格式化日期转化为时间戳

PHP 函数 strtotime — 将任何字符串的日期时间描述解析为 Unix 时间戳

 strtotime(string $datetime, int $now = time()): int

传入$datetime 即可将格式化时间转换为时间戳

$date = '2021-11-1 12:11:12';
echo strtotime($date) . "<br>";
// 输出 1635739872

$date = '2021年11月1日 12:11:12';
echo strtotime($date) . "<br>";
// 将没有任何输出或报错,不支持中文转换

$date = '2021/11/1 12:11:12';
echo strtotime($date) . "<br>";
// 输出 1635739872

echo date('Y年m月d日 H:i',strtotime($date));
// 输出 2021年11月01日 12:11
本文为 Wiki 文章,邀您参与纠错、纰漏和优化
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!