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:

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

Example

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

app/app.component.html<div>
  {{ myDate | date }}
</div>

The result of the executed code:

html<div>Dec 31, 2025</div>

Example

Now let's display a short date output:

app/app.component.html<div>
  {{ myDate | date:'shortDate' }}
</div>

The result of the executed code:

html<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:

app/app.component.html<div>
  {{ myDate | date:'fullDate' }}
</div>

The result of the executed code:

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

Practical tasks

Задание 1

Given date:

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

Format it as follows:

typescript'Jan 2, 2025'
Задание 2

Format the date from the previous task as follows:

typescript'1/2/25, 3:00 AM'
Задание 3

Format the date as follows:

typescript'1/2/25'
Задание 4

Format the date as follows:

typescript'January 2, 2025 at 3:00:00 AM GMT+3'
Задание 5

Format the date as follows:

typescript'Thursday, January 2, 2025'