Toufiqur Rahman
Toufiqur Rahman

Reputation: 212

Convert today date into UTC string

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

Upvotes: 2

Views: 3844

Answers (2)

user120242
user120242

Reputation: 15268

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'))

Upvotes: 1

Mridul
Mridul

Reputation: 1366

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());

Upvotes: 1

Related Questions