0

Any idea how to automatically set the time picker to the current time after opening it?

$('#StartDate').datetimepicker({
  value: new Date(),
  step: 15,
  closeOnDateSelect: true,
  format: 'm/d/Y H:i',
  mask: true
}).off('open.xdsoft focusin.xdsoft mousedown.xdsoft touchstart')

$('button').on('click', function() {
  $('#StartDate').datetimepicker('show')
});
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.full.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.min.css" integrity="sha256-DOS9W6NR+NFe1fUhEE0PGKY/fubbUCnOfTje2JMDw3Y=" crossorigin="anonymous" />

<input id="StartDate" type="text">
<button>Show</button>
evavienna
  • 1,059
  • 11
  • 29

1 Answers1

0

I think you could try putting the options of the datetimepicker on another variable so that you can modify them later? Like so:

var datepickerOptions = {
    value: new Date(),
    step: 15,
    closeOnDateSelect: true,
    format: 'm/d/Y H:i',
    mask: true
};

$('#StartDate').datetimepicker(datepickerOptions).off('open.xdsoft focusin.xdsoft mousedown.xdsoft touchstart');

And then for the changing of the value you can use the same datepickerOptions and just change the value so that everything remains the same:

$('button').on('click', function() {
    $('#StartDate').datetimepicker("destroy").val('');
   datepickerOptions.value = new Date();
   $('#StartDate').datetimepicker(datepickerOptions);
   $('#StartDate').datetimepicker("show");
});

Don't know if this is what you are looking for, hope it helps.

Leo
  • 956
  • 8
  • 24