php - 一年中的 PHP 错误日
问题描述
我正在尝试将一年中的某一天转换为日期。
所以没问题,我将 DateTime::createFromFormat 与 z 和 Y 一起使用。
DateTime::createFromFormat('z Y', '199 2020');
/*RESULT*/
object(DateTime)[3]
public 'date' => string '2020-07-19 12:45:24.000000' (length=26)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/Paris' (length=12)
但是当我测试结果时,我得到了错误的一年中的一天......
date('z Y', strtotime('2020-07-19'));
/*RESULT*/
'198 2020' (length=8)
所以我尝试这个
DateTime::createFromFormat('z Y', date('z Y', strtotime('2020-07-19')));
/*RESULT*/
object(DateTime)[3]
public 'date' => string '2020-07-20 12:52:10.000000' (length=26)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/Paris' (length=12)
如果我在此网站上查看 2020 年 199 年的某一天:https ://www.calendrier.best/numero-de-jour-2020.html
我得到 2020-07-17
我做错了什么??
解决方案
PHP 只检测一些标准,如您可以在此处看到的https://www.php.net/manual/de/datetime.formats.date.php
在您的第一个示例中,您定义了格式但strtotime()
没有此类参数
如果您将这些值作为变量,您可以mktime()
使用https://www.php.net/manual/de/function.mktime
但我建议总是在一月前给 PHP 一个月
推荐阅读
- python - Tweepy 没有在 anaconda jupyter 上运行
- java - 我很难跳到循环的正确部分
- c# - 将动画应用于情节提要中的 ModelVisual3D
- python - 简单功能不实习
- python - jinja2 剥离所有字母数字和特殊字符的方式?
- apache-spark - 加入横向视图 爆炸 Spark1 与 Spark2
- javascript - 如何正确使用 Redux 处理复杂的仪表板应用程序?
- c# - 我只需要输出在此控制台应用程序中打印的最后一个 int。我正在使用 foreach 循环。C# 控制台应用程序
- ios - 如何在 Swift 中对 SKStoreReviewController 进行单元测试
- javascript - 从数组中的对象获取布尔值,然后为其分配一个 DOM 属性