Seems the most foolproof way to start with a UTC date is to create a new Date object and use the setUTC… methods to set it to the date/time you want.

Then the various toLocale…String methods will provide localized output.

Example:

// This would come from the server.
// Also, this whole block could probably be made into an mktime function.
// All very bare here for quick grasping.
d = new Date();
d.setUTCFullYear(2004);
d.setUTCMonth(1);
d.setUTCDate(29);
d.setUTCHours(2);
d.setUTCMinutes(45);
d.setUTCSeconds(26);

console.log(d);                        // -> Sat Feb 28 2004 23:45:26 GMT-0300 (BRT)
console.log(d.toLocaleString());       // -> Sat Feb 28 23:45:26 2004
console.log(d.toLocaleDateString());   // -> 02/28/2004
console.log(d.toLocaleTimeString());   // -> 23:45:26

Some references:

  • toLocaleString
  • toLocaleDateString
  • toLocaleTimeString
  • getTimezoneOffset
Answer from kch on Stack Overflow
🌐
W3Schools
w3schools.com › jsref › jsref_tolocaledatestring.asp
W3Schools.com
The toLocaleDateString() method returns the date (not the time) of a date object as a string, using locale conventions. Date.toLocaleDateString(locales, options) JavaScript Dates · JavaScript Date Formats · JavaScript Date Get Methods · ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toLocaleDateString
Date.prototype.toLocaleDateString() - JavaScript | MDN
For implementations without internationalization support, toLocaleDateString() always uses the system's locale, which may not be what you want. Because any implementation that supports the locales and options parameters must support the Intl API, you can check the existence of the latter for support: ... function toLocaleDateStringSupportsLocales() { return ( typeof Intl === "object" && !!Intl && typeof Intl.DateTimeFormat === "function" ); }
Top answer
1 of 16
225

Seems the most foolproof way to start with a UTC date is to create a new Date object and use the setUTC… methods to set it to the date/time you want.

Then the various toLocale…String methods will provide localized output.

Example:

// This would come from the server.
// Also, this whole block could probably be made into an mktime function.
// All very bare here for quick grasping.
d = new Date();
d.setUTCFullYear(2004);
d.setUTCMonth(1);
d.setUTCDate(29);
d.setUTCHours(2);
d.setUTCMinutes(45);
d.setUTCSeconds(26);

console.log(d);                        // -> Sat Feb 28 2004 23:45:26 GMT-0300 (BRT)
console.log(d.toLocaleString());       // -> Sat Feb 28 23:45:26 2004
console.log(d.toLocaleDateString());   // -> 02/28/2004
console.log(d.toLocaleTimeString());   // -> 23:45:26

Some references:

  • toLocaleString
  • toLocaleDateString
  • toLocaleTimeString
  • getTimezoneOffset
2 of 16
66

You can do it with moment.js (deprecated in 2021)

It's best to parse your date string from UTC as follows (create an ISO-8601 compatible string on the server to get consistent results across all browsers):

var m = moment("2013-02-08T09:30:26Z");

Now just use m in your application, moment.js defaults to the local timezone for display operations. There are many ways to format the date and time values or extract portions of it.

You can even format a moment object in the users locale like this:

m.format('LLL') // Returns "February 8 2013 8:30 AM" on en-us

To transform a moment.js object into a different timezone (i.e. neither the local one nor UTC), you'll need the moment.js timezone extension. That page has also some examples, it's pretty simple to use.

Note: Moment JS recommends more modern alternatives, so it is probably not a good choice for new projects.

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toLocaleTimeString
Date.prototype.toLocaleTimeString() - JavaScript | MDN
The toLocaleTimeString() method of Date instances returns a string with a language-sensitive representation of the time portion of this date in the local timezone. In implementations with Intl.DateTimeFormat API support, this method delegates to Intl.DateTimeFormat.
🌐
W3Schools
devcom.w3schools.com › jsref › jsref_tolocaletimestring.asp
JavaScript Date toLocaleTimeString() Method
The toLocaleTimeString() method returns the time portion of a date object as a string, using locale conventions.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-date-tolocaledatestring-method
JavaScript Date toLocaleDateString() Method - GeeksforGeeks
July 11, 2025 - The code initializes a Date object and options for formatting. It then demonstrates the use of toLocaleDateString() to output the current date in different formats based on locale settings, with and without custom options.
🌐
W3Schools
www-db.deis.unibo.it › courses › TW › DOCS › w3schools › jsref › jsref_tolocaledatestring.asp.html
JavaScript toLocaleDateString() Method
The toLocaleDateString() method converts the date (not the time) of a Date object into a readable string, using locale conventions. ... Color Converter Google Maps Animated Buttons Modal Boxes Modal Images Tooltips Loaders JS Animations Progress Bars Dropdowns Slideshow Side Navigation HTML ...
🌐
W3schoolsapp
w3schoolsapp.com › jsref › jsref_tolocaledatestring.html
JavaScript toLocaleDateString() Method
The toLocaleDateString() method converts the date (not the time) of a Date object into a readable string, using locale conventions. ... Tabs Dropdowns Accordions Side Navigation Top Navigation Modal Boxes Progress Bars Parallax Login Form HTML Includes Google Maps Range Sliders Tooltips Slideshow ...
🌐
xjavascript
xjavascript.com › blog › how-do-you-format-a-date-time-in-typescript
How to Format Date/Time in TypeScript: Using toLocaleDateString with Practical Examples — xjavascript.com
Override with timeZone: const date = new Date('2024-01-05T12:30:00Z'); // 12:30 UTC // New York (UTC-5 in January: 7:30 AM local time → date is still Jan 5) const nyDate = date.toLocaleDateString('en-US', { timeZone: 'America/New_York', dateStyle: 'long' }); // Tokyo (UTC+9: 9:30 PM → date is Jan 5 + 9h = Jan 6) const tokyoDate = date.toLocaleDateString('ja-JP', { timeZone: 'Asia/Tokyo', dateStyle: 'long' }); console.log(nyDate); // "January 5, 2024" console.log(tokyoDate); // "2024年1月6日" (January 6, 2024 in Japanese)
Find elsewhere
🌐
Codecademy
codecademy.com › docs › javascript › dates › .tolocalestring()
JavaScript | Dates | .toLocaleString() | Codecademy
June 4, 2024 - In the example below, toLocaleString() formats the current date and time according to the long date format with the full weekday, month, day, and year in English (United States) locale: const specificDate = new Date('2024-05-16'); const locale = 'en-US'; const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', }; console.log(specificDate.toLocaleDateString(locale, options)); Copy to clipboard ·
🌐
W3Schools
w3schools.sinsixx.com › jsref › jsref_tolocaledatestring.asp.htm
JavaScript toLocaleDateString() Method - SinSiXX - W3Schools
Free HTML XHTML CSS JavaScript DHTML XML DOM XSL XSLT RSS AJAX ASP ADO PHP SQL tutorials, references, examples for web building.
🌐
TutorialsPoint
tutorialspoint.com › javascript › date_tolocaledatestring.htm
JavaScript Date toLocaleDateString() Method
This method returns only date (not time) of a date object as a string, using the locale conventions. In the following example, we are demonstrating the basic usage of JavaScript Date toLocaleDateString() method −
🌐
W3Schools
w3schools.com › jsref › tryit.asp
W3Schools online HTML editor
The W3Schools online code editor allows you to edit code and view the result in your browser
🌐
Codecademy
codecademy.com › docs › javascript › dates › .tolocaledatestring()
JavaScript | Dates | .toLocaleDateString() | Codecademy
June 2, 2023 - When used without any parameters, .toLocaleDateString() returns a string with the month, day, and year options defaulted to numeric. How they’re arranged and formatted depends on the default locale in which the method was used.
🌐
Droidscript
droidscript.org › javascript › Global_Objects › Date › toLocaleDateString().html
dateObj.toLocaleDateString()
function toLocaleDateStringSupportsLocales() { try { new Date().toLocaleDateString('i'); } catch (e) { return e​.name === 'RangeError'; } return false; } This example shows some of the variations in localized date formats. In order to get the format of the language used in the user interface of your application, make sure to specify that language (and possibly some fallback languages) using the locales argument: var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0)); // formats below assume the local time zone of the locale; // America/Los_Angeles for the US // US English uses month-day-year order console.log(date.toLocaleDateString('en-US')); // → "12/19/2012" // British English uses day-month-year order console.log(date.toLocaleDateString('en-GB')); // → "20/12/2012" // Korean uses year-month-day order console.log(date.toLocaleDateString('ko-KR')); // → "2012.
🌐
Medium
medium.com › geekculture › level-up-your-date-and-time-formatting-skills-in-javascript-866d8b656092
Level Up Your Date and Time Formatting Skills in JavaScript | by Danielle Dias | Geek Culture | Medium
May 26, 2023 - In addition to the specific date ... time portions of a Date object. To get a localized string representation of the full date and time, we can use toLocaleString() without any parameters....
🌐
Sentry
sentry.io › sentry answers › javascript › how do i format a date in javascript?
How do I Format a Date in JavaScript? | Sentry
If you are formatting many dates, use Intl.DateTimeFormat(), as it allows you to create an Intl.DateTimeFormat object that you can format multiple times using the format() method. You only define the locales and options once. ... const date = new Date(Date.UTC(2022, 10, 22, 9, 0, 0)); const date2 = new Date(Date.UTC(2022, 11, 22, 9, 0, 0)); const options = { weekday: "long", year: "numeric", month: "long", day: "numeric", }; console.log(date.toLocaleDateString("en-ZA", options)); // Tuesday, 22 November 2022 console.log(date.toLocaleDateString("ko", options)); // 2022년 11월 22일 화요일 const intDateFormat = new Intl.DateTimeFormat("en-ZA", options); console.log(intDateFormat.format(date)); // Tuesday, 22 November 2022 console.log(intDateFormat.format(date2)); // Thursday, 22 December 2022
Top answer
1 of 3
3

It looks like Chrome does not use the Windows regional settings, but its own settings instead. These are available via Settings > Advanced Settings > Language. However the date format is not explicitly defined, it is inferred from the language + country choice, for instance:

  • English (US) sets date format to mm/dd/yyyy
  • English (UK) sets date format to dd/mm/yyyy

(For anyone trying to change these, don't forget - like I did - to restart Chrome for the settings to take effect)

Back to the original question, it looks like it was legit to use toLocaleDateString() as long as the idea is to present the information in a format the human user understands. But this would be an ideal world, where every user has his/her browser properly configured. Instead, Chrome is set by default to English(US) as long as people leave it be in English, and it takes some googling (which most users won't do) to change these settings.

This makes it risky to use toLocaleDateString() even when not "relying on a particular format or locale". It looks like the only "serious" option for any cross-browser web application is to manage its own date format preferences (per user, of course...)

2 of 3
2

From the MDN:

"The exact format depends on the platform, locale and user's settings."

And,

"You shouldn't use this method in contexts where you rely on a particular format or locale."

Basically, "Why" is because that's how Chrome does it. If you need a specific format, you're going to have to specify it yourself.