# angular.filter.date

Work in Progress This page is currently being revised. It might be incomplete or contain inaccuracies.

## Description

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

`format` string can be composed of the following elements:

- `'yyyy'`: 4 digit representation of year (e.g. AD 1 => 0001, AD 2010 => 2010)
- `'yy'`: 2 digit representation of year, padded (00-99). (e.g. AD 2001 => 01, AD 2010 => 10)
- `'y'`: 1 digit representation of year, e.g. (AD 1 => 1, AD 199 => 199)
- `'MMMM'`: Month in year (January-December)
- `'MMM'`: Month in year (Jan-Dec)
- `'MM'`: Month in year, padded (01-12)
- `'M'`: Month in year (1-12)
- `'dd'`: Day in month, padded (01-31)
- `'d'`: Day in month (1-31)
- `'EEEE'`: Day in Week,(Sunday-Saturday)
- `'EEE'`: Day in Week, (Sun-Sat)
- `'HH'`: Hour in day, padded (00-23)
- `'H'`: Hour in day (0-23)
- `'hh'`: Hour in am/pm, padded (01-12)
- `'h'`: Hour in am/pm, (1-12)
- `'mm'`: Minute in hour, padded (00-59)
- `'m'`: Minute in hour (0-59)
- `'ss'`: Second in minute, padded (00-59)
- `'s'`: Second in minute (0-59)
- `'a'`: am/pm marker
- `'Z'`: 4 digit (+sign) representation of the timezone offset (-1200-1200)
- `'z'`: short form of current timezone name (e.g. PDT)

`format` string can also be the following default formats for `en_US` locale (support for other locales will be added in the future versions):

- `'long'`: equivalent to `'MMMM d, y h:mm:ss a z'` for en_US locale (e.g. September 3, 2010 12:05:08 pm PDT)
- `'medium'`: equivalent to `'MMM d, y h:mm:ss a'` for en_US locale (e.g. Sep 3, 2010 12:05:08 pm)
- `'short'`: equivalent to `'M/d/yy h:mm a'` for en_US locale (e.g. 9/3/10 12:05 pm)
- `'fullDate'`: equivalent to `'EEEE, MMMM d,y'` for en_US locale (e.g. Friday, September 3, 2010)
- `'longDate'`: equivalent to `'MMMM d, y'` for en_US locale (e.g. September 3, 2010
- `'mediumDate'`: equivalent to `'MMM d, y'` for en_US locale (e.g. Sep 3, 2010)
- `'shortDate'`: equivalent to `'M/d/yy'` for en_US locale (e.g. 9/3/10)
- `'longTime'`: equivalent to `'h:mm:ss a z'` for en_US locale (e.g. 12:05:08 pm PDT)
- `'mediumTime'`: equivalent to `'h:mm:ss a'` for en_US locale (e.g. 12:05:08 pm)
- `'shortTime'`: equivalent to `'h:mm a'` for en_US locale (e.g. 12:05 pm)

## Usage

### In HTML Template Binding

`{{ date_expression | date[:format] }}`

### In JavaScript

`angular.filter.date(date[, format])`

### Parameters

- `date – {(Date|number|string)} –`

  Date to format either as Date object, milliseconds (string or number) or ISO 8601 extended datetime string (yyyy-MM-ddTHH:mm:ss.SSSZ).

- `format(optional) – {string} –`

  Formatting rules (see Description). If not specified, Date#toLocaleDateString is used.

### Returns

`{string}` –

Formatted string or the input if input is not recognized as date/millis.

## Example

      <span ng:non-bindable>{{1288323623006 | date:'medium'}}</span>:
          {{1288323623006 | date:'medium'}}<br/>
      <span ng:non-bindable>{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}</span>:
         {{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}<br/>
      <span ng:non-bindable>{{1288323623006 | date:'MM/dd/yyyy @ h:mma'}}</span>:
         {{'1288323623006' | date:'MM/dd/yyyy @ h:mma'}}<br/>

      it('should format date', function(){
        expect(binding("1288323623006 | date:'medium'")).
           toMatch(/Oct 2\d, 2010 \d{1,2}:\d{2}:\d{2} (am|pm)/);
        expect(binding("1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'")).
           toMatch(/2010\-10\-2\d \d{2}:\d{2}:\d{2} \-?\d{4}/);
        expect(binding("'1288323623006' | date:'MM/dd/yyyy @ h:mma'")).
           toMatch(/10\/2\d\/2010 @ \d{1,2}:\d{2}(am|pm)/);
      });