要经历这样的所有星期日:
/*self::WEEK = 604800*/
/* 3600 * 24 * 7 looks like 7 days for me*/
$start = 1286053200;
for ($i=0; $i < 10; $i++) {
echo date('d.m.Y H:i:s.u, D (z)', $start) . ' (' . $start . ')<br/>';
$start += self::WEEK;
}
但在某些情况下我看到了:
03.10.2010 00:00:00.000000, Sun (275) (1286053200)
10.10.2010 00:00:00.000000, Sun (282) (1286658000)
17.10.2010 00:00:00.000000, Sun (289) (1287262800)
24.10.2010 00:00:00.000000, Sun (296) (1287867600)
31.10.2010 00:00:00.000000, Sun (303) (1288472400)
06.11.2010 23:00:00.000000, Sat (309) (1289077200) <--
13.11.2010 23:00:00.000000, Sat (316) (1289682000)
20.11.2010 23:00:00.000000, Sat (323) (1290286800)
27.11.2010 23:00:00.000000, Sat (330) (1290891600)
04.12.2010 23:00:00.000000, Sat (337) (1291496400)
换句话说,失去了一个小时!?在哪里?!
答案 0 :(得分:1)
答案 1 :(得分:1)
尝试使用strtotime()
$start = 1286053200;
for ($i=0; $i < 10; $i++) {
echo date('d.m.Y H:i:s.u, D (z)', strtotime(' +' . ($i * 7) . ' DAYS',$start)) . ' (' . $start . ')<br/>';
}
答案 2 :(得分:0)
我为similar problem创建了一个函数。也许你会发现它很有用。
function getDays($year, $dayofweek, $format, $timezone='UTC')
{
$fridays = array();
$startDate = new DateTime("{$year}-01-01 {$dayofweek}", new DateTimezone($timezone));
$year++;
$endDate = new DateTime("{$year}-01-01", new DateTimezone($timezone));
$int = new DateInterval('P7D');
foreach(new DatePeriod($startDate, $int, $endDate) as $d) {
$fridays[] = $d->format($format);
}
return $fridays;
}
$sundays = getDays('2010', 'Sunday', 'd.m.Y H:i:s.u, D (z)', 'America/New_York');
var_dump($sundays);