Convert today date into UTC string

Viewed 1520

I am trying to convert today date to UTC. Even though I used .toISOString() to change the time. I used

import {formatDate} from '@angular/common';
today = formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss', 'en'); 

How can I convert today in UTC format? Plz advise me

2 Answers

What I could understand from your question is that you want something like this

let d = new Date().toUTCString();
console.log(d);
console.log(new Date(d).toISOString());

Angular Docs:
formatDate
DatePipe (format string) docs
Use the timezone third parameter:

import {formatDate} from '@angular/common';
today = formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss', 'en', '+0000'); 

console.log(formatDate(new Date(), 'yyyy-MM-ddThh:mm:ssZZZZZ', 'en', 'GMT'))
Related