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>
Example 2
Display date in a custom format:
<div ng-app="myApp" ng-controller="datCtrl"> <p>Date = {{ today | date : "dd.MM.y" }}</p> </div>
Example 3
Display date using predefined formats:
<div ng-app="myApp" ng-controller="datCtrl"> <p>Date = {{ today | date : "fullDate" }}</p> </div>
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>
Example 5
Take a date as a date-time string:
<div ng-app=""> <p>Date = {{ "2016-01-05T09:05:05.035Z" | date }}</p> </div>
Syntax
{{ date | date : format : timezone }}
Parameter
Parameter | Description |
---|---|
format |
Optional. Used to display date formats, which can be one or more of the following:
The format value can also be one of the following predefined formats:
|
timezone | Optional. Used for formatting dates with time zones. |