Dan,
Try these routines:
function formatDate(date_obj) {
const monthNames = [
"Jan", "Feb", "Mar",
"Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct",
"Nov", "Dec"
];
let day = date_obj.getDate();
let monthIndex = date_obj.getMonth();
let year = date_obj.getFullYear();
return monthNames[monthIndex] + ' ' + day + ', ' + year;
}
function formatTime(date_obj) {
// formats a javascript Date object into a 12h AM/PM time string
var hour = date_obj.getHours();
var minute = date_obj.getMinutes();
var amPM = (hour > 11) ? "pm" : "am";
if (hour > 12) {
hour -= 12;
} else if (hour == 0) {
hour = "12";
}
if (minute < 10) {
minute = "0" + minute;
}
return hour + ":" + minute + amPM;
}
Use them like this:
let date = new Date();
let str = formatDate(date) + " @ " + formatTime(date);
This will give you the desired date format.
I hope this helps,
Yisrael