Answers for "javascript date to 12 hour time"

4

js get time in am

var time = new Date();
console.log(
  time.toLocaleString('en-US', { hour: 'numeric', hour12: true })
);
Posted by: Guest on April-28-2020
1

get the current date time in javascript in 12 hour format

//this will give you date object remove the outer new Date to have 
//it as string
const today = new Date(new Date().toLocaleString("en-US", {
    day: '2-digit',
    month: '2-digit',
    year: 'numeric',
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit',
    hour12: true
}));
Posted by: Guest on December-22-2020
0

javascript get 24 hour time

var options = { hour12: false };
console.log(date.toLocaleString('en-US', options));
Posted by: Guest on November-08-2020

Code answers related to "javascript date to 12 hour time"

Code answers related to "Javascript"

Browse Popular Code Answers by Language