step 1: Install reformat-date
npm install reformat-date --save
step 2: Require the package in your project using object destructuring
const { formatDate, formatTime } = require('reformat-date');
step 3: Pass in the current date as an argument and the format you want it to return (i.e 12hr/24hr) when you call the function
let currentDate = new Date();
let format = 'dd/mm/yyyy'; // or mm/dd/yyyy or yyyy/mm/dd returns in the specified format passed
formatDate(currentDate, format);
let currentDate = new Date();
let format = 'others'; // returns in this format; e.g Tuesday 24th of December, 2019
formatDate(currentDate, format);
let currentDate = new Date();
let format = '12h'; // returns 12h format along with either am or pm
formatDate(currentDate, format);
let currentDate = new Date();
let format = '24h'; // returns 24h format
formatDate(currentDate, format);
See here