回答
$newTimestamp = strtotime('+2 years', $timestamp);
根据需要替换“+2年”。
$date = new DateTime();
$date->add(new DateInterval('P10Y'));
增加了10年(10Y
)到 “今天”。但是,DateTime只能在PHP 5.3中使用。
+1,不知道那个!在旁注中,你知道一些关于v5.3的新东西的一些很好的文本/书籍/教程吗?除官方手册外。 – Czechnology 2011-03-02 20:18:40
不是手动。不过,php网站有一个很好的更新日志/迁移教程。我倾向于避免使用PHP书籍,因为它们要么过时了,写得不好(例如,导致你编写非常糟糕的不安全代码),或者只是错误的。 – 2011-03-02 20:20:02
不完全正确:DateTime自5.2开始,仅为5.3添加了DateInterval。 – tobyS 2011-03-02 20:26:09
当你这样做时你应该考虑一件事。
$newTimestamp = strtotime('+2 years', $timestamp);
这增加了2年(720或721天)。如果你只想保持相同的日期和月份,并在时间戳
中添加2个额外年份,则必须使用mktime。
例
$timestamp = mktime(0, 0, 0, $month, $day, $year+2);`
现在,您应该使用像Carbon这样的库在php中完成所有这些时间/日期的工作人员。与日期一起工作令人高兴。 – 2016-07-09 09:53:53
$date = "1998-08-14";
$newdate = strtotime ('+2 years' , strtotime ($date)) ;
$newdate = date ('Y-m-j' , $newdate);
echo $newdate;
回声
2000-08-14
- 1. 将时间添加到时间戳
- 2. 将时间添加到时间戳
- 3. Extjs-将时间戳添加到时间戳
- 4. PostgreSQL:从列值中将时间间隔添加到时间戳
- 5. ORACLE SQL:将时间添加到带时区的时间戳
- 6. 将3年添加到时间戳
- 7. 将时间戳添加到mp4容器
- 8. 将秒添加到时间戳
- 9. 如何将时间戳添加到TFSBuild.proj?
- 10. 将时间戳添加到文件JAVAR
- 11. 将时间戳记添加到pdf
- 12. 将值添加到时间戳
- 13. 将时间戳添加到文件名
- 14. Android将时间戳添加到文件
- 15. 如何将时间戳添加到OutputDebugString()?
- 16. 添加时间偏移量从GMT到Unix时间戳PHP
- 17. 使用PHP脚本解析时将时间戳添加到XML
- 18. 将日期和时间添加到MySQL中的时间戳中
- 19. 将工作时间添加到时间戳
- 20. 添加两个小时到时间戳
- 21. 为时间戳添加时间
- 22. 如何使用Ecto的时间戳将时间戳添加到现有表?
- 23. 如何动态添加时间间隔到时间戳?
- 24. PHP时间戳 - > strtotime - >时间戳
- 25. Java时间戳php时间戳
- 26. 添加1周时间戳
- 27. 无法添加时间戳
- 28. Convert.ToDatetime不添加时间戳
- 29. JavaScript php将时间戳添加到多个单元格
- 30. 在将数据加载到Hive表时添加时间戳
@NullUserException:看起来很明显,你会替换'2'和'N',和'$ timestamp'包含正确的时间戳。在Jeff的代码中,没有其他地方说'$ timestamp' = now。 – 2011-03-02 20:19:52
这是一个例子......但条件是,“根据需要替换+2年”:P – 2011-03-02 20:20:06
我已经+1了,但是我的选票已被封顶。 :) – 2011-03-02 20:20:33