How to get the time on page load using jquery

277 views Asked by At

I am using bootstrap-timepicker.

On page load I'm trying to get the current time from that picker.

$('#starts-on').timepicker(...???  //dunno what to use );

I have found the page load function but how to get the time?

1

There are 1 answers

0
AudioBubble On

You can do it like this:

$('#starts-on').timepicker('setTime', new Date().getHours() + ':' + new Date().getMinutes());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-timepicker/0.5.2/js/bootstrap-timepicker.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-timepicker/0.5.2/css/bootstrap-timepicker.min.css" rel="stylesheet" />

<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" />


<div class="bootstrap-timepicker">
  <input id="starts-on" type="text" class="input-small">
  <i class="icon-time"></i>
</div>