angularjsHow do I format a date in AngularJS?
AngularJS provides a great way to format dates using the date
filter. This filter can be used in HTML templates as well as in JavaScript code.
The general syntax for the date
filter is as follows:
{{ expression | date : format : timezone }}
expression
is the date object or a number (milliseconds since UTC epoch)format
is a string of tokens that represent the output formattimezone
is an optional parameter that specifies the timezone to use
For example, to format a date object myDate
to show the date in the format dd/MM/yyyy
, we can use the following code:
{{ myDate | date : 'dd/MM/yyyy' }}
The output of the above code would be something like 10/07/2020
.
The format
parameter accepts a wide range of tokens that can be used to customize the output. A full list of supported tokens can be found here.
Helpful links
More of Angularjs
- How can I create an editable AngularJS application?
- How do I implement one-way binding in AngularJS?
- How can I become an Angular expert from a beginner level?
- How can I use Angular to zoom in and out of a div?
- How do I use Angular Zone to run my code?
- How do I use Angular to zip files?
- How can I use Angular and Zorro together to create a software application?
- How can I use Angular to zoom in on an image?
- How can I use Zone.js with Angular to detect and act upon asynchronous events?
- How do I use Angular Zone to detect and run Angular change detection?
See more codes...