user734119
user734119

Reputation: 113

Angular DatePipe Output - show UTC instead of GMT

Is there a way I can use Angular DatePipe to specify a format that shows "UTC" instead of "GMT". Example Format:

{{currentDate | date:'dd/MM/yyyy hh:mm:ss a (O)'}}

Output: 17/09/2021 10:50:32 AM (GMT-4)

Is there a way I can get the following output instead:

Output: 17/09/2021 10:50:32 AM (UTC-4)

i.e. where it says GMT, the output should say UTC instead

Upvotes: 0

Views: 2024

Answers (2)

Meqwz
Meqwz

Reputation: 1491

Since this is purley presentational, and the times of GMT and UTC are always the same, you could create a pipe:

@Pipe({
  name: 'utc',
})
export class UtcPipe implements PipeTransform {
  transform(dateTime: string): string {
    return dateTime.replace('GMT', 'UTC');
  }
}

And then the template:

{{ currentDate | date: 'dd/MM/yyyy hh:mm:ss a (O)' | utc }}

Stackblitz here.

I've also added the above answer and it doesn't work.

Upvotes: 1

Damian
Damian

Reputation: 1374

{{ currentDate | date:'dd/MM/yyyy hh:mm:ss a (O)':'UTC' }}

Upvotes: 0

Related Questions