DateFilter class
Formats date to a string based on the requested format. See Dart http://api.dartlang.org/docs/releases/latest/intl/DateFormat.html for full formating options.
medium
: equivalent toMMM d, y h:mm:ss a
for en_US locale (e.g. Sep 3, 2010 12:05:08 pm)short
: equivalent toM/d/yy h:mm a
for en_US locale (e.g. 9/3/10 12:05 pm)fullDate
: equivalent toEEEE, MMMM d, y
for en_US locale (e.g. Friday, September 3, 2010)longDate
: equivalent toMMMM d, y
for en_US locale (e.g. September 3, 2010)mediumDate
: equivalent toMMM d, y
for en_US locale (e.g. Sep 3, 2010)shortDate
: equivalent toM/d/yy
for en_US locale (e.g. 9/3/10)mediumTime
: equivalent toh:mm:ss a
for en_US locale (e.g. 12:05:08 pm)shortTime
: equivalent toh:mm a
for en_US locale (e.g. 12:05 pm)
Usage:
{{ date_expression | date[:format] }}
@NgFilter(name:'date') class DateFilter { static Map<String, String> MAP = { 'medium': 'MMM d, y h:mm:ss a', 'short': 'M/d/yy h:mm a', 'fullDate': 'EEEE, MMMM d, y', 'longDate': 'MMMM d, y', 'mediumDate': 'MMM d, y', 'shortDate': 'M/d/yy', 'mediumTime': 'h:mm:ss a', 'shortTime': 'h:mm a', }; Map<num, NumberFormat> nfs = new Map<num, NumberFormat>(); /** * [date]: Date to format either as Date object, milliseconds * ([string] or [num]) or various ISO 8601 datetime string formats * (e.g. `yyyy-MM-ddTHH:mm:ss.SSSZ` and its shorter versions like * `yyyy-MM-ddTHH:mmZ`, `yyyy-MM-dd` or `yyyyMMddTHHmmssZ`). If no * timezone is specified in the string input, the time is considered to * be in the local timezone. * * [format]: Formatting rules (see Description). If not specified, * mediumDate is used * */ call(date, [format = r'mediumDate']) { if (date == '' || date == null) return date; if (date is String) date = DateTime.parse(date); if (date is num) date = new DateTime.fromMillisecondsSinceEpoch(date); if (!(date is DateTime)) return date; var nf = nfs[format]; if (nf == null) { if (MAP.containsKey(format)) { format = MAP[format]; } nf = new DateFormat(format); } return nf.format(date); } }
Static Properties
Map<String, String> MAP #
static Map<String, String> MAP = { 'medium': 'MMM d, y h:mm:ss a', 'short': 'M/d/yy h:mm a', 'fullDate': 'EEEE, MMMM d, y', 'longDate': 'MMMM d, y', 'mediumDate': 'MMM d, y', 'shortDate': 'M/d/yy', 'mediumTime': 'h:mm:ss a', 'shortTime': 'h:mm a', }
Properties
Map<num, NumberFormat> nfs #
Map<num, NumberFormat> nfs = new Map<num, NumberFormat>()
Methods
dynamic call(date, [format = r'mediumDate']) #
date: Date to format either as Date object, milliseconds
(string
or num) or various ISO 8601 datetime string formats
(e.g. yyyy-MM-ddTHH:mm:ss.SSSZ
and its shorter versions like
yyyy-MM-ddTHH:mmZ
, yyyy-MM-dd
or yyyyMMddTHHmmssZ
). If no
timezone is specified in the string input, the time is considered to
be in the local timezone.
format: Formatting rules (see Description). If not specified, mediumDate is used
call(date, [format = r'mediumDate']) { if (date == '' || date == null) return date; if (date is String) date = DateTime.parse(date); if (date is num) date = new DateTime.fromMillisecondsSinceEpoch(date); if (!(date is DateTime)) return date; var nf = nfs[format]; if (nf == null) { if (MAP.containsKey(format)) { format = MAP[format]; } nf = new DateFormat(format); } return nf.format(date); }