dzava / calendar-month
v1.1.1
2019-04-18 01:13 UTC
Requires
- php: >=5.6
- nesbot/carbon: ^1.20.0|^2.16
Requires (Dev)
- phpunit/phpunit: ^6.1|^7.0
This package is auto-updated.
Last update: 2024-09-18 13:05:14 UTC
README
创建月份实例
use Dzava\CalendarMonth\Month; new Month(); // current month new Month(5); // may of current year new Month(5, 2019); // may of 2019
获取月份中的日期
要获取月份中的日期数组,请使用days()
方法。
use Dzava\CalendarMonth\Month; $month = new Month(5, 2018); $days = $month->days(); // array(31) { // [0] => class Carbon\Carbon {} // 2018-05-01 // ... // [30] => class Carbon\Carbon {} // 2018-05-31 // }
要获取月份每周的日期列表,请使用weeks()
方法。
use Dzava\CalendarMonth\Month; $month = new Month(5, 2018); $weeks = $month->weeks(); // array(5) { // [0] => array(7) { // [0] => class Carbon\Carbon {} // 2018-04-29 // ... // [6] => class Carbon\Carbon {} // 2018-05-05 // } // ... // [4] => array(7) {} // 2018-05-27 - 2018-06-02 // }
默认情况下,周从星期日开始。如果您想将周从不同的天开始,请使用weekStartsAt($day)
方法。0(星期日)到6(星期六)。
检查
要检查给定的日期是否属于该月份,请使用contains($day)
方法。日期可以是Carbon
实例,或者任何Carbon
构造函数支持的任何其他格式。
use Dzava\CalendarMonth\Month; $month = new Month(5, 2018); $month->contains('2018-05-02'); // true $month->contains('2018-04-02'); // false