Zamora's Blog

Get 12 hour time from JS Date Object

March 13, 2023

// Create Date Object
const date = new Date();
// Pass options to toLocaleString method
const time = date.toLocaleString('en-US', { hour: 'numeric', minute:'numeric', hours12: true });
// The log should look something like this '10:29 PM'
console.log(time)

© Andrew Zamora 2023