从今天开始(PHP),如何计算和获取过去的日期(例如3周前) [英] How to calculate and get a date in the past (e.g. 3 weeks ago) from today's date (PHP)

查看:118
本文介绍了从今天开始(PHP),如何计算和获取过去的日期(例如3周前)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个消息过滤脚本,我通常使用这个脚本来获取当前日期:

I have a news filtering script and I use this usually to get the current day:

echo date('j n Y');

哪些返回类似于1 1 2011年。我想做的是能够返回日期一周前相对于当前的日期/日期,以便它将返回只是例子(2010年12月25日),如果我选择得到1周前。如果我想要得到相对于当前日子的3个星期前的日子和月份以及3周。

Which returns something like 1 1 2011. What I want to do is being able to return the date a week ago relative to current date/day so that it would return just example (25 12 2010) if I choose to get 1 week ago. And so on if I want to get the day and month and year 3 weeks ago relative to current day.

我不知道这是可能的吗?鉴于我只需要使用当前的日期和年份来检索过去的日期,我应该可以将过去的日期作为日期,月份和年份在脚本中使用。

I do not know is that possible? given that I only have to use the current day month and year to retrieve past date, and I should be able to retrieve the past date as day, month, and year to use in the script.

如果我的问题不清楚,请让我知道。我很抱歉,

If my question is not clear, please let me know. I apologize.

推荐答案

strtotime 将在unix时间给您一个过去的日期,然后您可以将其输入到日期函数中:

strtotime will give you a past date in unix time, which you can then feed into the date function:

echo date('j n Y', strtotime("-3 weeks"))

这篇关于从今天开始(PHP),如何计算和获取过去的日期(例如3周前)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆