Skip to main content

๐Ÿฅญ Leap Year

zjkalLess than 1 minute

๐Ÿฅญ Leap Year

Tips

It is more convenient to use than the native method

isLeapYear()

Determine whether the specified date is a leap year

Parameters

ParameterIntroductionRequire
datetimeAny format time string or timestampOptional, defaults to the current time

Return Values

'true' if it's a leap year, 'false' if it's otherwise

Example code

/* Determine whether the specified date is a leap year */
TimeHelper::isLeapYear('2020-3-2 10:15:33');
// true

/* Determine if this year is a leap year */
TimeHelper::isLeapYear();
// false

daysInYear()

Count the number of days in the year in which the specified date is located

Parameters

ParameterIntroductionRequire
datetimeAny format time string or timestampOptional, defaults to the current time

Return Values

Returns the number of days in the year in which the specified date is located

Example code

/* Calculate the number of days in the current year for the following dates */
TimeHelper::daysInYear(1646360133);
// 365

daysInMonth()

Count the number of days in the month in which the specified date falls on

Parameters

ParameterIntroductionRequire
datetimeAny format time string or timestampOptional, defaults to the current time

Return Values

Returns the number of days in the month in which the specified date falls on

Example code

/* Calculate the number of days in the month for the following dates */
TimeHelper::daysInMonth('2020-2-1');
// 29

/* Calculate the number of days in the month */
TimeHelper::daysInMonth();
// 31