为什么会发生这种情况的第一天(可能是原因Carbon
扩展DateTime
这),以及如何从Carbon
例如更换时区时,得到正确的一周?年无效/周联合在一年
use Carbon\Carbon;
$wet = Carbon::parse('2017-01-02 00:47:21', 'WET');
$cet = Carbon::parse('2017-01-02 00:47:21', 'CET');
$new = $cet->copy()->tz('WET');
print_r([
'cet->format(ATOM)' => $cet->format(Carbon::ATOM), //prints: 2017-01-02T00:47:21+01:00
'cet->format(Y W)' => $cet->format('Y W'), //prints: 2017 01
'wet->format(ATOM)' => $wet->format(Carbon::ATOM), //prints: 2017-01-02T00:47:21+00:00
'wet->format(Y W)' => $wet->format('Y W'), //prints: 2017 01
'new->format(ATOM)' => $new->format(Carbon::ATOM), //prints: 2017-01-01T23:47:21+00:00
'new->format(Y W)' => $new->format('Y W'), //prints: 2017 52
]);
还有一个简单的例子:
print_r([
Carbon::create(2017, 1, 1, 0, 0, 1)->format('Y W'), //prints: 2017 52
Carbon::create(2016, 12, 31, 23, 59, 59)->format('Y W'), //prints: 2016 52
]);
那么,那些当地时间有一个1小时的偏移量。从00:47转换得到前一天的23:47 **。你期待什么结果? –
事实证明,这是问题的日期,而不是时区本身。当日期更改为当年第一个星期一之前的一天时,则“weekOfYear”字段会更改,但不会更改实际的“年份”。我已经发布了一个答案。 – Azder