You can use toLocaleString
(there is also toLocaleTimeString
if you don't need the date):
alert(new Date('2020-01-01T00:00:00Z').toLocaleString(undefined, {
timeZone: 'America/Los_Angeles'
}))
// Output: 12/31/2019, 4:00:00 PM
This example uses a fixed time to show the relation between input and output. To use the current time, just use new Date()
without initial value.
The first parameter is the locale. The undefined
here means that it's the current system locale, so the format (not the timezone) will be based on the user's settings (for example, on my machine it outputs 31.12.2019, 16:00:00
). You can also set a fixed locale there if you want, for example en-US
.