DateUtils

object DateUtils

Date/time parsing, formatting, and arithmetic helpers shared across all Kotlin targets.

Formatters render US-style MM/DD dates; the *Now helpers default to the system time zone rather than assuming a region. Declared as an object so its extensions are brought in by member import (e.g. import com.pambrose.common.util.DateUtils.toMMDDYY).

Properties

Link copied to clipboard

The elapsed Duration from this instant until now, or Duration.ZERO if the receiver is null.

Functions

Link copied to clipboard
fun LocalDate.abbrevDayOfWeek(): String
fun LocalDateTime.abbrevDayOfWeek(): String

Returns the abbreviated day-of-week name (e.g., "Mon", "Tue").

Link copied to clipboard
fun LocalDateTime?.age(timeZone: TimeZone): Duration

The elapsed Duration from this date-time until now, interpreting the receiver in timeZone, or Duration.ZERO if the receiver is null.

Link copied to clipboard

Returns the current moment from the system clock as an Instant.

Link copied to clipboard
fun localDateNow(timeZone: TimeZone = TimeZone.currentSystemDefault()): LocalDate

The current date in timeZone (the system default zone unless specified).

Link copied to clipboard
fun localDateTimeNow(timeZone: TimeZone = TimeZone.currentSystemDefault()): LocalDateTime

The current date-time in timeZone (the system default zone unless specified).

Link copied to clipboard
fun String.parseToLocalDate(): LocalDate

Parses this ISO-8601 date string (e.g. "2024-03-15") into a LocalDate.

Link copied to clipboard
fun String.parseToLocalDateTime(): LocalDateTime

Parses this ISO-8601 date-time string (e.g. "2024-03-15T08:30:45") into a LocalDateTime.

Link copied to clipboard
fun String.parseToLocalTime(): LocalTime

Parses this ISO-8601 time string (e.g. "13:45:30") into a LocalTime.

Link copied to clipboard

Truncates this Duration down to whole units and returns its Duration.toString form.

Link copied to clipboard
fun LocalDateTime.toCreated(): String

Wraps toMMDDYYYYHHMM in a "(Created …)" label, e.g. "(Created 04/10/2026 14:30)".

Link copied to clipboard
fun LocalDate.toDashedYYYYMMDD(): String

Formats this LocalDate as ISO-style YYYY-MM-DD, e.g. "2026-04-10".

Link copied to clipboard
fun LocalDateTime.toFullDateString(): String

Formats this LocalDateTime as a full date string, e.g., "Mon 04/10/26 14:30:00".

fun LocalDateTime.toFullDateString(timeZone: TimeZone): String

Formats this LocalDateTime as a full date string suffixed with the UTC offset for timeZone, e.g., "Mon 04/10/26 14:30:00 -04:00" (a zero offset renders as "Z").

Link copied to clipboard
fun LocalDateTime.toISO8601(): String

Formats this LocalDateTime as an ISO-8601 string with a trailing Z, dropping any fractional-seconds component (e.g. 2024-03-15T08:30:45.123 becomes "2024-03-15T08:30:45Z").

Link copied to clipboard
fun LocalDateTime.toLogString(): String

Formats this LocalDateTime as a log-friendly timestamp with milliseconds, e.g. "04/10/26 14:30:45.123" (MM/DD/YY HH:MM:SS.mmm).

Link copied to clipboard
fun LocalDate.toMMDD(): String

Formats this LocalDate as MM/DD, e.g. "04/10".

Link copied to clipboard
fun LocalDate.toMMDDYY(): String

Formats this LocalDate as MM/DD/YY (two-digit year), e.g. "04/10/26".

Link copied to clipboard
fun LocalDate.toMMDDYYYY(): String

Formats this LocalDate as MM/DD/YYYY, e.g. "04/10/2026".

Link copied to clipboard
fun LocalDateTime.toMMDDYYYYHHMM(): String

Formats this LocalDateTime as MM/DD/YYYY HH:MM, e.g. "04/10/2026 14:30".

Link copied to clipboard
fun LocalDate.toUTCDateTime(): LocalDateTime

Returns the last minute of this LocalDate in UTC, i.e. 23:59:00.001 of the same day.