获得30天的追溯日期以及时间 [英] Get 30 days back date along with time

查看:106
本文介绍了获得30天的追溯日期以及时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算从现在(例如8月14日23:06)到30天(例如8月14日23:06)过去30天的php中的精确时间。我写了这篇文章,其中当前datetime在$ d1中,过去30天datetime在$ d2中,但是以某种方式我没有得到正确的结果。知道吗?

I want to calculate EXACT past 30 days time period in php from now (for example 30 aug 14 23:06) to 30 days back (for example 1 aug 14 23:06). I wrote this where current datetime goes in $d1 and past 30 days datetime goes in $d2 but somehow i am not getting correct results. Any idea?

$url=$row["url"];
$pageid=getPageID($url);
$date=date('y-m-d g:i');
$d1=strtotime($date);
$d2=date(strtotime('today - 30 days'));

谢谢

推荐答案

该问题很可能是由于 date()调用格式错误引起的。传递给 date()的第一个参数应为格式(如文档),第二个应为可选时间戳。

The problem is likely caused by the malformed date() call. The first argument passed to date() should be the format (as shown in the Docs) and the second should be an optional timestamp.

尝试一下:

$d2 = date('c', strtotime('-30 days'));

PHPFiddle

简而言之,整个代码段可以简化为

As a short aside, the whole snippet can be simplified as follows:

$url = $row["url"];
$pageid = getPageID($url);
$date = date('y-m-d g:i');
$d1 = time();
$d2 = date('y-m-d g:i', strtotime('-30 days'));

这篇关于获得30天的追溯日期以及时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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