0 votes
263 views
in JavaScript by
how to get time in am/pm format in javascript? Or javascript time format am pm

1 Answer

0 votes
by (3.7k points)
Use following method to get time in AM and PM:

function timeFormatter(dateTime){
    var date = new Date(dateTime);
   var amPm,hour;
    if (date.getHours()>=12){
        hour = parseInt(date.getHours()) - 12;
        amPm = "PM";
    } else {
        hour = date.getHours();
        amPm = "AM";
    }
    var time = hour + ":" + date.getMinutes() + "" + amPm;
    return time;
}

Share:- Whatsapp Facebook Facebook


Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.

Categories

...