Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在阅读 strtotime() 函数的 PHP 手册时,我得到了一个解释很糟糕的“注释”——这样说:
注意: 不建议将此函数用于数学运算。最好在 PHP 5.3 及更高版本中使用 DateTime::add() 和 DateTime::sub(),或者在 PHP 5.2 中使用 DateTime::modify()。
“数学运算”是什么意思?...当然我知道一般的数学运算是什么,但这是什么意思?
为什么它不是“可取的”?
任何人都可以向我展示一个“不建议”的使用示例并解释原因吗?
谢谢。
您可以添加和减去日期以获取日期间隔。DateTime 对此更好,因为它会为您考虑闰年和夏令时等因素,而您必须手动使用strtotime().
strtotime()