Hi Friends 👋,
Welcome to Infinitbility ❤️!
Today, we are going to learn How to convert date to utc format in typescript, here we will use built-in method .toUTCString()
to convert date to utc date.
First, we will create sample new date()
object variable, after then, we will use .toUTCString()
method to convert it on utc date format.
let’s dive in code…
let date = new Date();
console.log(date); // 2022-04-24T11:26:53.690Z
let utcDate: string = date.toUTCString()
console.log(utcDate) // 'Sun, 24 Apr 2022 11:39:49 GMT'
Well, when you run above code, you can able to see date converted in utc date format.
For now, let’s check the output.
Output
All the best 👍.