Sadique Here
Sadique Here

Reputation: 53

Custom GMT format date pipe in Angular

I'm using angular default date pipe for formatting my date, using this code.

{{'27-04-2021 08:30:00' | utcDate | date: 'EE, d MMMM OOOO'}}

The result is Tue, 27 April GMT+05:30

I have to show the result as Tue, 27 April GMT+5:30

I have to format the GMT format from XX:XX to X:XX.

Thanks.

Upvotes: 1

Views: 388

Answers (1)

N.F.
N.F.

Reputation: 4184

Define this method in your component.

  replaceZone = (val: string | null): string => {
    if (val == null) {
      return '';
    }
    return val.replace(/0(\d:\d{2})$/, '$1');
  }

Then call like this.

{{replaceZone('27-04-2021 08:30:00' | utcDate | date: 'EE, d MMMM OOOO')}}

Upvotes: 1

Related Questions