Formats a given date as a simple HH:MM(:SS) string.

Type signature

(date: Date, showSeconds?: boolean) => string

Examples

formatTime(
  new Date("2019-02-24T01:12:34"),
);
// ⇒ "01:12"
Try in REPL
formatTime(
  new Date("2019-02-24T01:12:34"),
  true,
);
// ⇒ "01:12:34"
Try in REPL

Questions

  • How to render a date in a HH:MM format?
  • How to render a date in a HH:MM:SS format?

TypeScript sourceJavaScript source