Frenz
Frenz

Reputation: 747

Format UTC using datepipe

I want to format the UTC datetime to 'dd/MM/yyyy hh:mm:ss a'. I tried this using the datepipe. However it converts it to the localtime. How can I format UTC to the required format.

Stackblitz link: https://stackblitz.com/edit/angular-oxr43w

Thanks in advance.

Upvotes: 16

Views: 28848

Answers (2)

victorperezpiqueras
victorperezpiqueras

Reputation: 375

A simpler solution is to use the short parameter value set to "UTC":

<p>
  UTC: {{date | date: 'short':'UTC'}}
</p>

Angular pipes cast dates to locale timezone unless you specify it: angular -datepipes

Upvotes: 6

Danylo Gudz
Danylo Gudz

Reputation: 2646

Date pipe accepts a timezone check the docs

<p>
  UTC: {{date | date:"dd/MM/yyyy hh:mm:ss a":"+0000"}}
</p>

Check this out

Upvotes: 27

Related Questions