首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用strtotime获取过去的日期

使用strtotime获取过去的日期
EN

Stack Overflow用户
提问于 2021-01-10 09:56:14
回答 1查看 32关注 0票数 0
代码语言:javascript
复制
$month = date('m', strtotime('-19 years'));
$day = date('d', strtotime('-19 years'));
$year = date('Y', strtotime('-19 years'));

这正确地得到了19年前的月/日/年,这一天(2021年1月8日)分别是2002年1月8日。我怎么能做到19年零1天前? 19年零1个月前? 19年零1天零1个月前?等。

对于第一种情况(19年零一天前),$month = date('m', strtotime('-19 years -1day'))不起作用。

EN

回答 1

Stack Overflow用户

发布于 2021-01-10 10:00:05

strtotime()接受第二个参数,它是用于相对时间的基准日期。所以你可以从现在开始减去一天,然后使用-19 years

代码语言:javascript
复制
strtotime('-19 years', strtotime('-1 day'))
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65649487

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档