i am using bootstrap dateTimePicker.
Because the dateTimePicker works, the input needs to be in this format:
30/07/2019 23:59:59
.
The dateTimePicker works fine, i initialize it with this function and it works as i want:
<div class="form-group">
<div class='input-group date' id='datetimepicker2'>
<input type='text' class="form-control " id="datepick2" name="transaction_date_from"/>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
var d = new Date();
$("#datetimepicker2").datetimepicker({
defaultDate: new Date(d.getFullYear(),d.getMonth(),d.getDate(),23,59,59,00),
format: 'DD/MM/YYYY HH:mm:ss',
sideBySide: true,
showTodayButton: true,
showClear: true,
});
$('#datetimepicker2').datetimepicker({format: 'LT'}).on('dp.show', function(event) {
$(".bootstrap-datetimepicker-widget").find('.btn[data-action="togglePeriod"]').hide();
});
What i'm trying to do is that i have a <button>
that when is clicked it has to restore to the "defaultDate" the dateTimePicker.
What i've tried is:
var d = new Date();
var dateTo = new Date(d.getFullYear(),d.getMonth(),d.getDate(),23,59,59,00);
$("#datepick2").val(dateTo);
but instead of getting the same result as when i initialize the dateTimePicker, i get
Tue Jul 30 2019 23:59:59 GMT+0200 (Ora legale dell’Europa centrale)
.
So, my question is: how can i format the date as i want? Is there a bootstrap function that can do it?
Is there some function that can do it? I've seen the other question but it don't seem to answer my question.