What's a simple way to convert between an am/pm time to 24 hour time in javascript

前端 未结 5 1145
独厮守ぢ
独厮守ぢ 2021-02-03 15:51

I\'ve been playing with jquery and I\'ve run myself into a time problem. I\'ve got 3 time input select boxes, one for hours, one for minutes, and one for the Meridian. I need to

5条回答
  •  北海茫月
    2021-02-03 16:44

    I got it with a few people's answers.

    var time = "";
    var hour = Number($("#EventCloseTimeHour option:selected").text());
    if($("#EventCloseTimeMeridian option:selected").text() == 'PM'){
        hour = String((hour%12) + 12);
    }
    hour = hour < 10 ? "0" + hour : hour;
    time +=hour+":"+ $("#EventCloseTimeMin option:selected").text() + ":00";
    

提交回复
热议问题