0

In my Angular application I am trying to use Datepipe to convert date into GMT format and display. I see in a blog that Datepipe uses systems locale to convert the date. How can I convert into GMT.

Assuming the date is 6/19/2023 12:00:00 AM, I want to dislay XXXXX (gmt-5) I tried following code snippet which is not working.

new Date(datePipe.transform(new Date(6/19/2023 12:00:00 AM, 'MM/DD/YY'))
Hien Nguyen
  • 24,551
  • 7
  • 52
  • 62
user1015388
  • 1,283
  • 4
  • 25
  • 45

1 Answers1

1

For converting to GMT-5, you can use transform as this code

constructor(private datePipe: DatePipe) {
    const date = new Date('6/19/2023 12:00:00 AM');
    this.formattedDate = this.datePipe.transform(date, 'short', '-0500');
    console.log(this.formattedDate); // Display the formatted date
}

Demo code: https://stackblitz.com/edit/angular-ivy-hnkmjs

Hien Nguyen
  • 24,551
  • 7
  • 52
  • 62