⊗jsagPmPpDt 55 of 97 menu

Formatting Dates with Pipes in Angular

Using the DatePipe channel, we can set a specific format for the output date. This channel can accept the following parameters for the date display format:

Format Equivalent Example (for en-US locale)
'short' 'M/d/yy, h:mm a' 12/31/25, 3:00 AM
'medium' 'MMM d, y, h:mm:ss a' Dec 31, 2025, 3:00:00 AM
'long' 'MMMM d, y, h:mm:ss a z' December 31, 2025 at 3:00:00 AM GMT+3
'full' 'EEEE, MMMM d, y, h:mm:ss a zzzz' Wednesday, December 31, 2025 at 3:00:00 AM GMT+03:00
'shortDate' 'M/d/yy' 12/31/25
'mediumDate' 'MMM d, y' Dec 31, 2025
'longDate' 'MMMM d, y' December 31, 2025
'fullDate' 'EEEE, MMMM d, y' Wednesday, December 31, 2025
'shortTime' 'h:mm a' 3:00 AM
'mediumTime' 'h:mm:ss a' 3:00:00 AM
'longTime' 'h:mm:ss a z' 3:00:00 AM GMT+3
'fullTime' 'h:mm:ss a zzzz' 3:00:00 AM GMT+03:00

Examples

Let's look at the channel's operation using examples. To do this, in the component class, we'll set the myDate property, into which we'll write the date:

export class AppComponent { public myDate: number = Date.parse('2025-12-31'); }

Example

Let's output our date without passing any parameters to the channel:

<div> {{ myDate | date }} </div>

The result of the executed code:

<div>Dec 31, 2025</div>

Example

Now let's display a short date output:

<div> {{ myDate | date:'shortDate' }} </div>

The result of the executed code:

<div>12/31/25</div>

Example

Let's display our date and at the same time find out what day of the week it falls on:

<div> {{ myDate | date:'fullDate' }} </div>

The result of the executed code:

<div>Wednesday, December 31, 2025</div>

Practical tasks

Given date:

public myDate: number = Date.parse('2025-01-02');

Format it as follows:

'Jan 2, 2025'

Format the date from the previous task as follows:

'1/2/25, 3:00 AM'

Format the date as follows:

'1/2/25'

Format the date as follows:

'January 2, 2025 at 3:00:00 AM GMT+3'

Format the date as follows:

'Thursday, January 2, 2025'
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline