PkDateFormatter class
Locale-aware date and time formatting utilities.
All methods accept an optional locale parameter. When omitted, the
method falls back to the default locale or the system locale.
PkDateFormatter.shortDate(DateTime.now()) // '2/19/2026'
PkDateFormatter.longDate(DateTime.now()) // 'February 19, 2026'
PkDateFormatter.time(DateTime.now()) // '3:45 PM'
PkDateFormatter.time(DateTime.now(), use24h: true) // '15:45'
PkDateFormatter.dateTime(DateTime.now()) // 'Feb 19, 3:45 PM'
PkDateFormatter.relative(DateTime.now()
.subtract(const Duration(hours: 2))) // '2 hours ago'
PkDateFormatter.monthYear(DateTime.now()) // 'February 2026'
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
dateTime(
DateTime date, {Locale? locale}) → String -
Formats
dateas a compact date-and-time string:Dec 25, 2:30 PM. -
longDate(
DateTime date, {Locale? locale}) → String -
Formats
dateas a long human-readable date:December 25, 2024. -
monthYear(
DateTime date, {Locale? locale}) → String -
Formats
dateas month and year only:December 2024. -
relative(
DateTime date, {DateTime? now}) → String -
Formats
dateas a relative human-readable string. -
shortDate(
DateTime date, {Locale? locale}) → String -
Formats
dateas a short numeric date:12/25/2024. -
time(
DateTime date, {Locale? locale, bool use24h = false}) → String -
Formats the time portion of
date.