【发布时间】:2015-05-12 01:20:28
【问题描述】:
我需要从当前开始每周获取周一至周日的范围。
这是我想出的:
$range = 0;
$weekNumber = date("W", strtotime(date('l j F Y') . ' ' . ($range) . ' days'));
$weekYear = date("Y", strtotime(date('l j F Y') . ' ' . ($range) . ' days'));
$week_array = getWeekDates($weekNumber, $weekYear);
function getWeekDates($week, $year) {
$dto = new DateTime();
$ret['mon'] = $dto->setISODate($year, $week)->format('Y-m-d');
$ret['tue'] = $dto->modify('+1 days')->format('Y-m-d');
$ret['wed'] = $dto->modify('+1 days')->format('Y-m-d');
$ret['thu'] = $dto->modify('+1 days')->format('Y-m-d');
$ret['fri'] = $dto->modify('+1 days')->format('Y-m-d');
$ret['sat'] = $dto->modify('+1 days')->format('Y-m-d');
$ret['sun'] = $dto->modify('+1 days')->format('Y-m-d');
return $ret;
}
它可以在我的本地 WampServer (5.3.4) 上运行,但是当我尝试在 Godaddy (5.2.17) 上运行它时,出现此错误:
致命错误:在 /home/.....php 中的非对象上调用成员函数 format() 在线 ($ret['mon'] = $dto->setISODate($年,$week)->format('Y-m-d');)
【问题讨论】:
-
godaddy 和本地 wamp 服务器上的 php 版本是什么?可能不兼容
标签: php date fatal-error