Open In App

Angular 10 DatePipe API

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:




import { Component, OnInit } 
from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent {
    today: number = Date.now();
}




<p>Date {{today | date}}</p>
  
     
<p>Time {{today | date:'h:mm a z'}}</p>

Output:

Example 2:




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent {
    today: number = Date.now();
}




<p>Date {{today | date}}</p>
  
     
<p>Time {{today | date:'h:m:s'}}</p>

Output:


Article Tags :