d() function for comprehensive date handling with timezone support, arithmetic, comparisons, and formatting.
Creating dates
From string
With timezone
Current date/time
Date components
Getters
| Method | Example | Result |
|---|---|---|
.year() | d("2024-01-15").year() | 2024 |
.month() | d("2024-01-15").month() | 1 |
.day() | d("2024-01-15").day() | 15 |
.weekday() | d("2024-01-15").weekday() | 1 (Monday) |
.hour() | d("2024-01-15 14:30").hour() | 14 |
.minute() | d("2024-01-15 14:30").minute() | 30 |
.second() | d("2024-01-15 14:30:45").second() | 45 |
.dayOfYear() | d("2024-01-15").dayOfYear() | 15 |
.quarter() | d("2024-01-15").quarter() | 1 |
.timestamp() | d("2024-01-15").timestamp() | 1705276800000 |
Setters
Date arithmetic
Adding time
Subtracting time
Duration units
| Unit | Aliases |
|---|---|
| Year | y, year, years |
| Month | M, month, months |
| Week | w, week, weeks |
| Day | d, day, days |
| Hour | h, hour, hours |
| Minute | m, minute, minutes |
| Second | s, second, seconds |
Date comparisons
Comparison methods
Comparison with granularity
Comparison operators
Range checks
Calculating differences
Start and end of periods
Timezone conversion
Relative dates
Validation
Leap years
Formatting
Format codes
| Code | Description | Example |
|---|---|---|
%Y | 4-digit year | 2024 |
%m | Month (01-12) | 01 |
%d | Day (01-31) | 15 |
%H | Hour (00-23) | 14 |
%M | Minute (00-59) | 30 |
%S | Second (00-59) | 45 |
%A | Full weekday | Monday |
%a | Abbreviated weekday | Mon |
%B | Full month | January |
%b | Abbreviated month | Jan |
%j | Day of year | 015 |