Laravel – 關於 Carbon 日期處理的二月問題
目前使用指定屬性或 set 方法的方式,在 Carbon v2.24 會出現指定 2 月但顯示 3 月的錯誤。
1 2 3 4 5 6 7 |
$carbon = new Carbon(); $carbon->setYear(2019); $carbon->setMonth(2); $carbon->setDay(2); dd($carbon->toDateString()); // 2019-03-02 |
1 2 3 4 5 6 7 |
$carbon = new Carbon(); $carbon->year = 2019; $carbon->month = 2; $carbon->day = 2; dd($carbon->toDateString()); // 2019-03-02 |
後來在較新的官方文件看到,還是建議使用預設的用法
1 2 3 4 |
$carbon = Carbon::create(2019, 2, 2); dd($carbon->toDateString()); //2019-02-02 |