Results for “year”
Small, practical examples. Search by task or narrow things down below.
Check the Gregorian leap-year rule
Java: Use Year.isLeap rather than checking divisibility by four alone.
Java✓ Tested
Determine whether a year is a leap year
Python: Use calendar.isleap rather than a simplified divisibility-by-four check.
Python✓ Tested
Read an ISO week year and week number
Java: Use ISO week fields together because a week can belong to the previous calendar year.
Java✓ Tested
Extract part of a date
Read a calendar component with EXTRACT.
EXTRACT✓ Tested
Advance a date by a number of days
Python: Use timedelta so month and year boundaries are handled automatically.
Python✓ Tested
Find the last day of a month
Java: Use YearMonth so leap years and month lengths are handled by the calendar library.
Java✓ Tested
Find the length of a calendar month
C#: DaysInMonth applies the Gregorian leap-year rules.
C#✓ Tested
Find the number of days in a month
Python: Use calendar.monthrange to account for leap years.
Python✓ Tested
Find the number of days in a month
PowerShell: DaysInMonth handles leap-year February correctly.
PowerShell✓ Tested
Format a timestamp
Extract a year and month from ISO timestamp text.
strftime✓ Tested
Read an ISO week date
Linux Commands: Use ISO week year, week number, and weekday directives together.
Linux Commands✓ Tested
Read an ISO week number
Python: Use isocalendar because ISO week years can differ from calendar years near January.
Python✓ Tested