Reputation: 111
I am needing to convert the standard Date(); JS object to the following format: 7/13/2021 8:47:58 PM (M/d/yyyy HH:mm:ss Z)
I'm struggling to get this EXACT format in the simplest way possible. This is what I have so far:
var d = new Date,
dformat = [d.getMonth()+1,
d.getDate(),
d.getFullYear()].join('/')+' '+
[d.getHours(),
d.getMinutes(),
d.getSeconds()].join(':');
console.log(dformat);
I am struggling to get the time zone, which I am conjecturing adds the AM/PM (I could very well be mistaken).
Any help is greatly appreciated!
Upvotes: 1
Views: 324
Reputation: 190
var d = new Date,
dformat = [d.getMonth()+1,
d.getDate(),
d.getFullYear()].join('/')+' '+
d.toLocaleTimeString('en-US')
console.log(dformat);
Upvotes: 2