为什么日期格式转换和时间戳转换的输出不同?

Why is the output of date format conversion and timestamp conversion different?

下面的时间戳和日期转换代码反映了不同的输出。我还设置了默认时区,但没有任何乐趣。请有人告诉我出了什么问题,因为我是第一次注意到这一点?我也在实时服务器上试过,也是一样。

echo date("d F, Y", 1578079200).'<br/>'; //03 January, 2020
echo strtotime("3 January, 2020").'<br/>'; //1609705200
echo date("d F, Y", 1609705200).'<br/>'; //03 January, 2021

非常感谢

strtotime("3 January, 2020")

给你 今年 年的 1 月 3 日(剧透:在 20:20 小时,分钟)。

strtotime("3 January 2020")

为您提供 2020 年 1 月 3 日的日期(剧透:在 00:00 小时,分钟)。


Why is the output of date format conversion and timestamp conversion different?

因为格式不同。每种不同的格式转换不同。

如果您准确了解日期格式并想解析日期,请参阅DateTime::parseFromFormat():

<?php
$date = DateTime::createFromFormat('d F, Y', '3 January, 2020');
echo $date->format('Y-m-d'), "\n";
echo $date->getTimestamp(), "\n";
2020-01-03
1578007000