angular.module.ng.$filter.date

Description

Formats date to a string based on the requested format.

format string can be composed of the following elements:

format string can also be one of the following predefined localizable formats:

format string can contain literal values. These need to be quoted with single quotes (e.g. "h 'in the morning'"). In order to output single quote, use two single quotes in a sequence (e.g. "h o''clock").

Usage

In HTML Template Binding

{{ date_expression | date[:format] }}

In JavaScript

$filter('date')(date[, format])

Parameters

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)/);
  });