EasyDateTimeFormatter class

A pre-compiled date formatter for high-performance scenarios.

Unlike EasyDateTime.format which parses the pattern on every call, EasyDateTimeFormatter parses the pattern once during initialization. This provides significant performance benefits in loops or hot paths.

Basic Usage

final formatter = EasyDateTimeFormatter('yyyy-MM-dd HH:mm');
for (final date in dates) {
  print(formatter.format(date));
}

Using Named Constructors

final isoFormatter = EasyDateTimeFormatter.isoDate();
print(isoFormatter.format(EasyDateTime.now())); // '2025-12-15'

Caching Behavior

Formatters are cached by pattern string. Creating multiple formatters with the same pattern returns the same instance:

final f1 = EasyDateTimeFormatter('yyyy-MM-dd');
final f2 = EasyDateTimeFormatter('yyyy-MM-dd');
print(identical(f1, f2)); // true

For long-running applications or when using many unique patterns, use clearCache to release memory:

EasyDateTimeFormatter.clearCache();

Constructors

EasyDateTimeFormatter(String pattern)
Creates a EasyDateTimeFormatter with the given pattern.
factory
EasyDateTimeFormatter.isoDate()
ISO 8601 date format: yyyy-MM-dd
factory
EasyDateTimeFormatter.isoDateTime()
ISO 8601 date and time format: yyyy-MM-dd'T'HH:mm:ss
factory
EasyDateTimeFormatter.isoTime()
ISO 8601 time format: HH:mm:ss
factory
EasyDateTimeFormatter.rfc2822()
RFC 2822 format: EEE, dd MMM yyyy HH:mm:ss xxxx
factory
EasyDateTimeFormatter.time12Hour()
12-hour time format: hh:mm a
factory
EasyDateTimeFormatter.time24Hour()
24-hour time format: HH:mm
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
pattern String
The pattern string used by this formatter.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addPattern(String additionalPattern) EasyDateTimeFormatter
Creates a new formatter by appending additionalPattern to this formatter's pattern.
combineFormatters(EasyDateTimeFormatter formatter2) EasyDateTimeFormatter
Creates a new formatter by combining this formatter's pattern with formatter2's pattern.
format(EasyDateTime date) String
Formats the date using the pre-compiled pattern.
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

clearCache() → void
Clears all cached formatters.