Skip Navigation

Using toLocaleTimeString without displaying seconds

Useful referencing here

  • This will output the users current time in their default locale. For example the following would output 11:37 PM if I am visiting the page at 23:37 in the UK.
    Using users current localejavascript
    console.log(
      date.toLocaleTimeString([], {
        hour: '2-digit',
        minute: '2-digit',
      }),
    );
  • If we want to specify a specific format to output for example Korean, we can specify the format as a string in the first parameter of toLocaleTimeString. The result of the following code will be 오전 11:40
    Specify a localejavascript
    const date = new Date();
    console.log(
      date.toLocaleTimeString('ko-KR', {
        hour: '2-digit',
        minute: '2-digit',
      }),
    );
    // 오전 11:40