DatePipe

export class DatePipe

exported from angular2/common defined in angular2/src/common/pipes/date_pipe.ts (line 19)

Formats a date value to a string based on the requested format.

WARNINGS:

Usage

expression | date[:format]

where expression is a date object or a number (milliseconds since UTC epoch) and format indicates which date/time components to include:

Component Symbol Short Form Long Form Numeric 2-digit
era G G (AD) GGGG (Anno Domini) - -
year y - - y (2015) yy (15)
month M MMM (Sep) MMMM (September) M (9) MM (09)
day d - - d (3) dd (03)
weekday E EEE (Sun) EEEE (Sunday) - -
hour j - - j (13) jj (13)
hour12 h - - h (1 PM) hh (01 PM)
hour24 H - - H (13) HH (13)
minute m - - m (5) mm (05)
second s - - s (9) ss (09)
timezone z - z (Pacific Standard Time) - -
timezone Z Z (GMT-8:00) - - -

In javascript, only the components specified will be respected (not the ordering, punctuations, ...) and details of the formatting will be dependent on the locale. On the other hand in Dart version, you can also include quoted text as well as some extra date/time components such as quarter. For more information see: https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/intl/intl.DateFormat.

format can also be one of the following predefined formats:

Timezone of the formatted text will be the local system timezone of the end-users machine.

Examples

Assuming dateObj is (year: 2015, month: 6, day: 15, hour: 21, minute: 43, second: 11) in the local time and locale is 'en-US':

{{ dateObj | date }} // output is 'Jun 15, 2015' {{ dateObj | date:'medium' }} // output is 'Jun 15, 2015, 9:43:11 PM' {{ dateObj | date:'shortTime' }} // output is '9:43 PM' {{ dateObj | date:'mmss' }} // output is '43:11' @Component({ selector: 'date-example', template: `<div> <p>Today is {{today | date}}</p> <p>Or if you prefer, {{today | date:'fullDate'}}</p> <p>The time is {{today | date:'jmZ'}}</p> </div>` }) export class DatePipeExample { today: number = Date.now(); }

Annotations

@Pipe({name: 'date', pure: true})

@Injectable()


Members

transform(value: any, args: any[]) : string

Not Yet Documented

supports(obj: any) : boolean

Not Yet Documented