Date

Date.prototype.toLocaleString

Returns a string with a language-sensitive representation of this date, including both date and time

Syntax

JavaScript
date.toLocaleString(locales?, options?)

Parameters

ParameterTypeDescription
localesstring | string[]A BCP 47 language tag or array of tags
optionsIntl.DateTimeFormatOptionsFormatting options

Return Value

A string representing the date and time

Examples

Basic Usage
const date = new Date('2024-06-15T14:30:00');
console.log(date.toLocaleString('en-US'));
// '6/15/2024, 2:30:00 PM'
Practical Example
const date = new Date();
console.log(date.toLocaleString('en-GB', {
  dateStyle: 'full',
  timeStyle: 'short',
}));
Advanced Usage
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

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.