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-ddfactory - EasyDateTimeFormatter.isoDateTime()
-
ISO 8601 date and time format:
yyyy-MM-dd'T'HH:mm:ssfactory - EasyDateTimeFormatter.isoTime()
-
ISO 8601 time format:
HH:mm:ssfactory - EasyDateTimeFormatter.rfc2822()
-
RFC 2822 format:
EEE, dd MMM yyyy HH:mm:ss xxxxfactory - EasyDateTimeFormatter.time12Hour()
-
12-hour time format:
hh:mm afactory - EasyDateTimeFormatter.time24Hour()
-
24-hour time format:
HH:mmfactory
Properties
Methods
-
addPattern(
String additionalPattern) → EasyDateTimeFormatter -
Creates a new formatter by appending
additionalPatternto 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
dateusing 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.