js12 hours convert code





function f2(){
    d=new Date();
    hours=d.getHours();//24
    min=d.getMinutes();
    sec=d.getSeconds();
    ampm="am";

    // if(hours>12){
    //     hours=hours%12;
    //     if(hours==0){
    //         hours=12;
    //     }
    //     ampm="pm";
    // }
    // if(min<10){
    //     min='0'+min;
    // }
    // if(sec<10){
    //     sec='0'+sec;
    // }
    ampm=hours>=12?'pm':'am';
hours=hours%12;
hours=hours?hours:12;
min=min<10?'0'+min:min;
sec=sec<10?'0'+sec:sec;




    d1=hours+":"+min+":"+sec+""+ampm;
    //console.log(d1);
    document.getElementById('a').innerHTML=d1;
}

Comments

Popular posts from this blog

interview questions js[ Anurag Singh ProCodrr]

reactnative_creation