Last Updated : 04 Aug, 2021
In this article, we are going to see what is DatePipe in Angular 10 and how to use it.
DatePipe is used to format a date value according to locale rules.
Syntax:
{{ value | date }}
Approach:
Parameters:
Example 1:
app.component.ts
import { Component, OnInit }
from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
today: number = Date.now();
}
app.component.html
<p>Date {{today | date}}</p>
<p>Time {{today | date:'h:mm a z'}}</p>
Output:
Example 2:
app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
today: number = Date.now();
}
app.component.html
<p>Date {{today | date}}</p>
<p>Time {{today | date:'h:m:s'}}</p>
Output:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4