Example 1 — Format the Same Date in Two Locales
Compare US and British date order for December 20, 2012.
const date = new Date(2012, 11, 20); // Dec 20, 2012 (local)
console.log(date.toLocaleDateString("en-US")); // "12/20/2012"
console.log(date.toLocaleDateString("en-GB")); // "20/12/2012" How It Works
- Build a local date. Month index
11is December. - Format for the US.
en-USuses month/day/year →"12/20/2012". - Format for Britain.
en-GBuses day/month/year →"20/12/2012". - Same instant, different labels. Choose the locale that matches your users.

