Date.prototype.toLocaleString
Returns a string with a language-sensitive representation of this date, including both date and time
Syntax
date.toLocaleString(locales?, options?)Parameters
| Parameter | Type | Description |
|---|---|---|
| locales | string | string[] | A BCP 47 language tag or array of tags |
| options | Intl.DateTimeFormatOptions | Formatting options |
Return Value
A string representing the date and time
Examples
const date = new Date('2024-06-15T14:30:00');
console.log(date.toLocaleString('en-US'));
// '6/15/2024, 2:30:00 PM'const date = new Date();
console.log(date.toLocaleString('en-GB', {
dateStyle: 'full',
timeStyle: 'short',
}));const date = new Date('2024-06-15T14:30:00');
console.log(date.toLocaleString('ja-JP'));
// '2024/6/15 14:30:00'Understanding Date.prototype.toLocaleString
The Date.prototype.toLocaleString method in JavaScript returns a string with a language-sensitive representation of this date, including both date and time. It belongs to the Date object and is one of the most widely used methods for working with date values in modern JavaScript and TypeScript applications.
The method signature is date.toLocaleString(locales?, options?). It accepts 2 parameters: locales, options. When called, it returns a string representing the date and time. Understanding when and how to use toLocaleString() helps you write more expressive, readable code.
Common use cases for Date.prototype.toLocaleString include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like date-tolocaledatestring, date-tolocaletimestring, date-toisostring, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Date.prototype.toLocaleString is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
Date.prototype.toLocaleDateStringReturns a string with a language-sensitive representation of the date portion of this date
Date.prototype.toLocaleTimeStringReturns a string with a language-sensitive representation of the time portion of this date
Date.prototype.toISOStringReturns a string in simplified extended ISO format (ISO 8601), which is always 24 or 27 characters long
More Date Methods
Other methods in the Date object
Related Tools
More Date Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.