简体   繁体   中英

How to get the time on page load using jquery

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?

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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM