Intl.DateTimeFormat().resolvedOptions().timeZone defaults to "America/Los_Angeles" - why?

docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions

var tz = Intl.DateTimeFormat().resolvedOptions().timeZone
console.log(tz)
>> "America/Los_Angeles"

//from MDN docs

const region1 = new Intl.DateTimeFormat('zh-CN'); //China locale
const options1 = region1.resolvedOptions().timeZone;
console.log(options1) 
>> "America/Los Angeles"

WTF? What am I missing? I had some of my friends in the East Coast test it, and they also got America/Los_Angeles.

I assume you are running this on a browser.

The timezone defaults to that provided by the browser.

Setting locale to zh-CN doesn’t automatically change the timezone, how could it know which chinese or other timezone to choose? Although you can set the timezone at the same time.

const region1 = new Intl.DateTimeFormat('zh-CN', { timeZone: 'UTC' });

Your script is more confusing than the docs, as you have a constant named options and are assigning a value to it which is not an options object.

I see - so from what I see, it’s impossible to gather the client timezone from the browser?

Are your friends setting a specific timezone like some browser extensions or VPN do?

Not to my knowledge… when you ran the code snippets what did you get? You can run the momentjs stuff on Runkit.

I’m thinking about using Day.js to format time again - its smaller and has better functionality on browsers.

Running on firefox showed my local timezone.

If you run on runkit, it should show timezone of runkit’s server … is that what you want?

1 Like

ah, I see - that’s why! I whip up a quick static site later so it’ll show the client time zone :+1: