dump(date('Y-m-d', strtotime('2018-10-1 +1 day')));

dump(date('Y-m-d', strtotime('2018-10-1 +1 week')));

dump(date('Y-m-d', strtotime('2018-10-1 +1 month')));

dump(date('Y-m-d', strtotime('2018-10-1 +1 year')));

dump(date('Y-m-d', strtotime('2018-10-1 -1 day')));

dump(date('Y-m-d', strtotime('2018-10-1 -1 week')));

dump(date('Y-m-d', strtotime('2018-10-1 -1 month')));

dump(date('Y-m-d', strtotime('2018-10-1 -1 year')));

同理,把2018-10-1换成变量,就可以做很多事了!

ps 由于每个月份的天数不一样 +/- 1 month 特殊日期会有误差

//获取上一个月日期方法

public function getBeforeMonthDate($currentDate)
{
$currentMonthDay = date('t', strtotime($currentDate));
$currentDay = date('d', strtotime($currentDate));
$yearMonth = date('Y-m', strtotime($currentDate));
$beforeMonth = date('Y-m-d', strtotime("$yearMonth -1 month"));
$beforeMonthDay = date('t', strtotime($beforeMonth));
if ($beforeMonthDay < $currentMonthDay && $beforeMonthDay < $currentDay) {
$beforeDate = date("Y-m-d", strtotime("last day of -1 month", strtotime($currentDate)));
} else {
$beforeDate = date('Y-m-d', strtotime("$currentDate -1 month"));
}
return $beforeDate;
}

最新文章

  1. scheduletask任务调度
  2. js闭包
  3. js 利用throw 写的一个小程序
  4. 键盘和alertView的冲突问题
  5. http 错误 500.21
  6. (转)RSA算法原理(二)
  7. Tomcat上的项目部署到WebLogic上の注意事项
  8. jansen字符串转换为xml格式
  9. ASP.Net自定义重写Http Server标头
  10. 关于javascript的slice方法
  11. Activity 与ListActivity的区别
  12. ios创建的sqlite数据库文件如何从ios模拟器中导出
  13. SqlServer sys.partition_view
  14. cmd正常启动tomcat,而 从eclipse启动出现 404
  15. 关于启动调试时,总是启动多个web端口的问题
  16. 1593: [Usaco2008 Feb]Hotel 旅馆
  17. iOS 科学计数法保留N位有效数字
  18. 【转】Jenkins 安装与配置
  19. 【一天一道LeetCode】#97. Interleaving String
  20. 五种IO模型透彻分析

热门文章

  1. React-Native:解决真机调试时候Could not get BatchedBridge, make sure your bundle is packaged properly
  2. 一个box四周边框阴影
  3. linux dd 本地挂载
  4. jdbc访问pipelinedb
  5. step_by_step_记录那些在VS上使用过的工具
  6. java编译带中文是显示乱码的错误
  7. 关于socket
  8. git pre-push hook
  9. SQL数据库索引理解与应用【转贴--收藏】
  10. 2019-04(1)(Python学习)