我是php的初学者。我正在尝试将 XML API 集成到我的系统中。调用代码是
$XML = simplexml_load_file('http://my.mydomain.com/stats/report.xml?api_key=XXXXXXXX&start_date='.date('Y-m-d').'&end_date='.date('Y-m-d'));
我需要做的是;
- 开始日期 = 昨天
- end_date = 今天
我找不到如何描述。
您可以strtotime()
像这样简单地使用调用:
$today = date('Y-m-d', strtotime('today') );
$yesterday = date('Y-m-d', strtotime('1 day ago') );
$Start_Date=date('d.m.Y',strtotime("-1 days"));
$End_Date = date('d.m.y', strtotime('today') );
PHP strtotime() 函数有助于:
你可以使用
$XML = simplexml_load_file('http://my.mydomain.com/stats/report.xml?api_key=XXXXXXXX&start_date='.date('Y-m-d',strtotime('yesterday')).'&end_date='.date('Y-m-d',strtotime('yesterday'));
是的,就这么简单,date('Ymd',strtotime('yesterday')) 给你昨天的日期!!
参考: http: //php.net/manual/en/function.strtotime.php
int strtotime ( string $time [, int $now = time() ] )
$time = 日期/时间字符串。有效格式在日期和时间格式中进行了说明。
$now = 这是时间戳的可选参数,用作计算相对日期的基础。