jQuery UI Timepicker

1

Good, I would like default to show me the current time, I do not know how to do, I have the grid with the hour and minute with PM / AM to choose, if I click "Now", if you give me the current time. But I would like the current time to be shown by default in the input without clicking. The format that shows me is "08:35 AM"

<div>
   <label for="hora">Hora</label>
   <?php echo form_input('hora',$venta->hora, ' id="hora" class="timepicker" size="6"'); ?> 
</div> 
<script type="text/javascript">
$('.timepicker').timepicker ({ 
          showPeriod: true 
        , showNowButton: true
        , showCloseButton: true
    });
</script>
    
asked by mer 01.10.2016 в 00:07
source

1 answer

0

If you want to show the current time in the timepicker you can do it directly with javascript and jquery, assuming you use the timepicker library for jquery below I'll give you an example:

var today = new Date(); // for now
var hour = today.getHours()+":"+today.getMinutes();

$('#hora').timepicker({ 'step': 1, timeFormat: 'H:i:s A' }).val(hour);
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <link rel="stylesheet" type="text/css" href="https://jonthornton.github.io/jquery-timepicker/jquery.timepicker.css" />
  <title>timepicker</title>
</head>
<body>
<div>
   <label for="hora">Hora</label>
   <input id="hora" class="timepicker" type="text">
</div> 

<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script src="https://jonthornton.github.io/jquery-timepicker/jquery.timepicker.js"></script>
</body>
</html>
    
answered by 01.10.2016 / 02:26
source