jquery Datepicker with masked input and current time

24 hr and standard AM/PM examples with masked input and current time

HTML

<script src="http://cloud.github.com/downloads/digitalBush/jquery.maskedinput/jquery.maskedinput-1.3.min.js"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css">
<input class="datepicker" type="text" size="30" /> AM / PM
<br />
<input class="datepicker24" type="text" size="30" /> 24 hour

JavaScript

function getTimeAmPm() {
    var date_o = new Date();
    var date_mins = date_o.getMinutes() < 10 ? "0" + date_o.getMinutes() : date_o.getMinutes();
    var date_hours = date_o.getHours() > 12 ? "0" + (date_o.getHours() - 12) : date_o.getHours();
    var date_am_pm = date_o.getHours() < 12 ?  " AM" : " PM";

    // handle midnight
    date_hours = date_hours === 0 ? 12 : date_hours;

        
    return "'" + date_hours + ":" + date_mins + " " + date_am_pm + "'";
}

function getTime24() {
    var date_o = new Date();
    var date_hours = date_o.getHours() < 10 ? "0" + date_o.getHours() : date_o.getHours();
    var date_mins = date_o.getMinutes() < 10 ? "0" + date_o.getMinutes() : date_o.getMinutes();


    return "'" + date_hours + ":" + date_mins + "'";
}

$(".datepicker").datepicker({dateFormat: 'yy-mm-dd ' + getTimeAmPm()});
$(".datepicker").mask("9999-99-99 99:99 aa");


$(".datepicker24").datepicker({dateFormat: 'yy-mm-dd ' + getTime24()});
$(".datepicker24").mask("9999-99-99 99:99");