Full width home advertisement

OpenCV

HTML

Post Page Advertisement [Top]

    In this post I am demontrating how Bootstrap Datetimepicker date-time value can change programmatically from JavaScript.
Bootstrap Datetimepicker  Change datetime

Add latest js and css script to get datetimepicekr

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.42/js/bootstrap-datetimepicker.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.42/css/bootstrap-datetimepicker.min.css" rel="stylesheet"></link>


HTML Code


<button  style="margin:50px 0px 0px 50px;" type="button" class="btn btn-success" onclick="setDate()" >Change Date</button>  
<div style="padding:25px;">
         <div style="width:200px;"  class='input-group date' id='datetimepicker_id'>
            <input id="datetimepicker_val_id" placeholder="To date"  type='text' class="form-control" />
            <span class="input-group-addon">
            <span class="glyphicon glyphicon-calendar"></span>
            </span>
         </div>
</div>

JavaScript

    Here I have used the time in 24 hour format(HH:mm:ss), for 12 hour format change HH:mm:ss to hh:mm:ss


function setDate(){ 
  var mydate = '25-12-2020 18:23:23' ; // string datetime format-- DD-MM-YYYY HH:mm:ss     
  $('#datetimepicker_id').data("DateTimePicker").date(mydate)
  $('#datetimepicker_id').data("DateTimePicker").viewDate(mydate);
}

//initilize datetimepicker
$(function () {
  $('#datetimepicker_id').datetimepicker({ 
      format : 'DD-MM-YYYY HH:mm:ss',
      date: new Date()
      });
  
 });
 

Demo

No comments:

Post a Comment

Bottom Ad [Post Page]

| Designed by Colorlib