Reputation: 747
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
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
Reputation: 2646
Date pipe accepts a timezone check the docs
<p>
UTC: {{date | date:"dd/MM/yyyy hh:mm:ss a":"+0000"}}
</p>
Upvotes: 27