Skip to main content

How to Use toLocaleTimeString() Without Seconds in JavaScript

The Date.prototype.toLocaleTimeString() method is a powerful tool for formatting a Date object's time into a human-readable, locale-sensitive string. By default, it often includes seconds, but in many UI designs, you only want to display the hours and minutes.

This guide will teach you how to use the options parameter of toLocaleTimeString() to customize its output and omit the seconds, giving you precise control over the time format.

The Core Method: toLocaleTimeString() and its options

The toLocaleTimeString() method is the standard, modern way to format time for display. Its real power comes from its second argument, an options object that lets you specify exactly which components of the time you want to display and how they should be formatted.

The Syntax

date.toLocaleTimeString(locales, options)

where:

  • locales (optional): A string or array of strings specifying the language and region (e.g., 'en-US', 'de-DE').
  • options (optional): An object that configures the output format.

Problem: by default, toLocaleTimeString() might include seconds, which you don't want.

let now = new Date();

// The default format might include seconds, depending on the locale.
console.log(now.toLocaleTimeString('en-US')); // # Output: 3:30:15 PM

The Solution: Specifying hour and minute

To show the time without seconds, you simply provide an options object that only includes the hour and minute properties. If you omit the second property, it will not be included in the output.

Solution:

let now = new Date();

let options = {
hour: '2-digit', // e.g., 03
minute: '2-digit', // e.g., 30
};

// Pass the options object as the second argument.
let timeWithoutSeconds = now.toLocaleTimeString('en-US', options);

console.log(timeWithoutSeconds); // # Output: 03:30 PM
note

This is the recommended best practice for formatting time without seconds.

How the options Object Works

The options object is the key to customizing the output. For time formatting, the main properties are:

PropertyPossible ValuesDescription
hour'numeric', '2-digit'Formats the hour.
minute'numeric', '2-digit'Formats the minute.
second'numeric', '2-digit'Formats the second.
hour12true, falseSpecifies whether to use 12-hour time (with AM/PM) or 24-hour time.

where:

  • 'numeric': Uses one or two digits as needed (e.g., 5).
  • '2-digit': Always uses two digits, adding a leading zero if necessary (e.g., 05).

By only specifying hour and minute in the options object, you are telling toLocaleTimeString() that you are not interested in the second component, so it is omitted from the final string.

A Note on Locales

The first argument to toLocaleTimeString() is the locale. This is a string that determines the language and regional formatting rules.

  • 'en-US': American English (e.g., 3:30 PM).
  • 'en-GB': British English (e.g., 15:30).
  • 'de-DE': German (e.g., 15:30).

If you omit this argument or pass an empty array ([]), the method will use the user's default locale from their browser or operating system settings.

let now = new Date();
let options = { hour: '2-digit', minute: '2-digit' };

// Use the visitor's default locale.
let userLocaleTime = now.toLocaleTimeString([], options);

// Use a specific locale.
let germanTime = now.toLocaleTimeString('de-DE', options);

Practical Example: A Reusable Formatting Function

This is a robust, reusable function that you can use throughout your application to format time consistently.

/**
* Formats a Date object to a time string (HH:MM AM/PM) without seconds.
* @param {Date} date The Date object to format.
* @param {string} locale The locale to use for formatting (e.g., 'en-US').
* @returns {string} The formatted time string.
*/
function formatTimeWithoutSeconds(date, locale = 'default') {
let options = {
hour: 'numeric',
minute: '2-digit',
};
return date.toLocaleTimeString(locale, options);
}

// Example Usage:
let eventTime = new Date('2025-10-27T14:05:00');

console.log(formatTimeWithoutSeconds(eventTime)); // # Output: 2:05 PM (in en-US)

Conclusion

The toLocaleTimeString() method is a powerful and flexible tool for formatting dates in a locale-sensitive way.

  • To remove seconds from the output, provide an options object that only includes the hour and minute properties.
  • Use the hour: '2-digit' and minute: '2-digit' options to ensure consistent, two-digit formatting.
  • Specify a locale (e.g., 'en-US') as the first argument for consistent formatting across all users, or omit it to use the user's local preference.