Date.prototype.toLocaleTimeString
Returns a string with a language-sensitive representation of the time portion of this date
Syntax
date.toLocaleTimeString(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 time portion
Examples
const date = new Date('2024-06-15T14:30:00');
console.log(date.toLocaleTimeString('en-US')); // '2:30:00 PM'const date = new Date();
const time = date.toLocaleTimeString('en-US', {
hour: '2-digit',
minute: '2-digit',
hour12: false,
});
console.log(time); // '14:30'const date = new Date('2024-06-15T09:05:00');
console.log(date.toLocaleTimeString('de-DE')); // '09:05:00'Understanding Date.prototype.toLocaleTimeString
The Date.prototype.toLocaleTimeString method in JavaScript returns a string with a language-sensitive representation of the time portion of this date. 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.toLocaleTimeString(locales?, options?). It accepts 2 parameters: locales, options. When called, it returns a string representing the time portion. Understanding when and how to use toLocaleTimeString() helps you write more expressive, readable code.
Common use cases for Date.prototype.toLocaleTimeString include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like date-tolocaledatestring, date-tolocalestring, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Date.prototype.toLocaleTimeString 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.