DateTimeExtensions
DateTime manipulation and formatting extension methods.
API Reference
Period Boundaries
| Method | Return | Description |
|---|---|---|
| StartOfDay(this DateTime) | DateTime | 00:00:00 of the day |
| EndOfDay(this DateTime) | DateTime | 23:59:59.999 of the day |
| StartOfWeek(this DateTime, DayOfWeek) | DateTime | First day of week |
| EndOfWeek(this DateTime, DayOfWeek) | DateTime | Last moment of week |
| StartOfMonth(this DateTime) | DateTime | First day of month |
| EndOfMonth(this DateTime) | DateTime | Last moment of month |
| StartOfYear(this DateTime) | DateTime | First day of year |
| EndOfYear(this DateTime) | DateTime | Last moment of year |
Date Checks
| Method | Return | Description |
|---|---|---|
| IsToday(this DateTime) | bool | Is current date |
| IsPast(this DateTime) | bool | Before now |
| IsFuture(this DateTime) | bool | After now |
| IsWeekend(this DateTime) | bool | Saturday or Sunday |
| IsWeekday(this DateTime) | bool | Monday to Friday |
| IsBetween(this DateTime, DateTime, DateTime) | bool | Within range |
Conversions
| Method | Return | Description |
|---|---|---|
| ToUnixTimeSeconds(this DateTime) | long | Unix timestamp (seconds) |
| ToUnixTimeMilliseconds(this DateTime) | long | Unix timestamp (ms) |
| ToIso8601(this DateTime) | string | ISO 8601 format |
| ToRelativeTime(this DateTime) | string | 2 hours ago |
| EnsureUtc(this DateTime) | DateTime | Ensures UTC kind |
| GetAge(this DateTime) | int | Age in years |