我如何獲得DatePeriod
對象的開始和結束日期?獲取PHP DatePeriod對象的開始日期和結束日期?
$today = new \DateTime(date('Y-m-d')); // 2012-05-30
$period = new \DatePeriod($today, new \DateInterval('P1M'), 1);
$stats = new UsageStatistics($period);
class UsageStatistics
{
protected $period, $sentEmailCount, $autoSentEmailCount;
public function __construct(\DatePeriod $period)
{
$this->period = $period;
// Current logged in user and email repository
$user = $this->getUser();
$repo = $this->getEmailRepository();
// Get the start and end date for the given period
$startDate = ...
$endDate = ...
$result = $repo->getAllSentCount($user, $startDate, $endDate);
// Assigning object properties
}
public function getSentEmailCount() { return $this->sentEmailCount; }
public function getAutoSentEmailCount() { return $this->autoSentEmailCount; }
}
很醜,你必須循環。不管怎麼說,還是要謝謝你。 – gremo
是的,我知道,我用ArrayObject嘗試過,但它沒有奏效。 – Boby
有趣的是,知道我正在尋找完全一樣的。看來,有一個補丁在那裏https://bugs.php.net/bug.php?id=53439但它是從2010年,所以...不知道 – KingCrunch