I want to set a timezone to a date. So basically a date should be display everytime taking into account that timezone. Also i want to use a native solution. I know that exists this solution:
const t = new Date(1641991591447).toLocaleString('en-GB', { timeZone: 'Europe/London' })
console.log(t)
But this returns 12/01/2022, 12:46:31
instead of 2022-01-12T12:46:31.447Z
this format. So how to get the last format taking into account the timezone?
In order to convert your date to the specified format (ISO date string), you can do this by simply creating a Date
constructor and using your date value as the input and chaining the toISOString
method to it.
const t = new Date(1641991591447).toISOString(); // 2022-12-01T12:46:31.000Z