How to display a Date object in a specific format using JavaScript?

Use the build-in toLocaleString()

const date = new Date();

const formattedDate = date.toLocaleString("en-GB", {
  day: "numeric",
  month: "short",
  year: "numeric",
  hour: "numeric",
  minute: "2-digit"
});

console.log(formattedDate); // '18 Jan 2020, 18:20'

Leave a Comment