AngularJS date Filter

Definition and Usage

date The filter formats the date into the specified format.

The date can be a date object, milliseconds, or a date-time string, such as "2016-01-05T09:05:05.035Z".

By default, the format is "MMM d, y" (Jan 5, 2016).

Related Pages

AngularJS Tutorial:Angular Filters

Example

Example 1

Display numbers in date format:

<div ng-app="myApp" ng-controller="datCtrl">
<p>Date = {{ today | date }}</p>
</div>

Try it yourself

Example 2

Display date in a custom format:

<div ng-app="myApp" ng-controller="datCtrl">
<p>Date = {{ today | date : "dd.MM.y" }}</p>
</div>

Try it yourself

Example 3

Display date using predefined formats:

<div ng-app="myApp" ng-controller="datCtrl">
<p>Date = {{ today | date : "fullDate" }}</p>
</div>

Try it yourself

Example 4

Display a combination of text and predefined date formats:

<div ng-app="myApp" ng-controller="datCtrl">
<p>Date = {{ today | date : "'today is ' MMMM d, y" }}</p>
</div>

Try it yourself

Example 5

Take a date as a date-time string:

<div ng-app="">
<p>Date = {{ "2016-01-05T09:05:05.035Z" | date }}</p>
</div>

Try it yourself

Syntax

{{ date | date : format : timezone }}

Parameter

Parameter Description
format

Optional. Used to display date formats, which can be one or more of the following:

  • "yyyy" Year (2016)
  • "yy" Year (16)
  • "y" Year (2016)
  • "MMMM" Month (January)
  • "MMM" Month (Jan)
  • "MM" Month (01)
  • "M" Month (1)
  • "dd" Date (06)
  • "d" Date (6)
  • "EEEE" Day of the week (Tuesday)
  • "EEE" Day of the week (Tue)
  • "HH" Hour, 00-23 (09)
  • "H" Hour 0-23 (9)
  • "hh" Hour in AM/PM (00-12), 00-12 (09)
  • "h" Hour in AM/PM (0-12), 0-12 (9)
  • "mm" Minutes (05)
  • "m" Minutes (5)
  • "ss" Seconds (05)
  • "s" Seconds (5)
  • "sss" Milliseconds (035)
  • "a" (AM/PM)
  • "Z" Time zone (-1200 to +1200)
  • "ww" Week (00-53)
  • "w" Week (0-53)
  • "G" Anno Domini
  • "GG" Anno Domini
  • "GGG" Anno Domini
  • "GGGG" Anno Domini

The format value can also be one of the following predefined formats:

  • "short" With "M/d/yy h:mm a" Same (1/5/16 9:05 AM)
  • "medium" With "MMM d, y h:mm:ss a" Same (Jan 5, 2016 9:05:05 AM)
  • "shortDate" With "M/d/yy" Same (1/5/16)
  • "mediumDate" With "MMM d, y" Same (Jan 5, 2016)
  • "longDate" With "MMMM d, y" Same (January 5, 2016)
  • "fullDate" With "EEEE, MMMM d, y" Same (Tuesday, January 5, 2016)
  • "shortTime" With "h:mm a" Same (9:05 AM)
  • "mediumTime" With "h:mm:ss a" Same (9:05:05 AM)
timezone Optional. Used for formatting dates with time zones.