How/Where does JavaScript detect the default locale?

I would just like to answer this in 2023 for anyone struggling with exactly the issue of the original post: where Date gets its default locale. Most Google results will land you on navigator.languages, but my machine was definitely not using those values. Here’s what I saw on my console:

new Date().toDateString()
// 'Fri Aug 04 2023'
navigator.languages
// (2) ['en-US', 'en']
new Date().toLocaleDateString()
// '04/08/2023'
new Date().toLocaleDateString(navigator.languages[0])
// '8/4/2023'

Though my languages are US-only, my machine region is set to Ireland, and toLocaleDateString was reading that somehow and formatting the date in the Irish style, DD/MM/YYYY, as opposed to the US style, MM/DD/YYYY. After 30+ minutes of searches and drudging through lacking documentation, I finally found this post, which led me to my answer.

At least in Chrome on MacOS, the Date object sources its locale from Intl.DateTimeFormat().resolvedOptions().locale, which was not documented anywhere that I could find. Hopefully this can save someone the frustration that I just went through.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)