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

Type signature

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

Examples

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

Questions

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

TypeScript sourceJavaScript source