Bootstrap datetimepicker get time
I am using Bootstrap datetimepicker in the insiders of my Meteor.JS app to have two time pickers. Below is the code I have so far detected an onChange event for each of the two time pickers in my form, but I cannot figure out how to get the selected time? So can someone please tell me how to do this? Thanks to
$('.set-start-time').datetimepicker({
pickDate: false
});
$('.set-end-time').datetimepicker({
pickDate: false
});
$('.set-end-time').on("dp.change",function (e) {
var now = $('.set-start-time').data("DateTimePicker").getDate();
var then = $('.set-end-time').data("DateTimePicker").getDate();
//Above code won't return time...
});
+3
source to share
1 answer
Hope this helps someone.
Html
<div name="startTime" class="input-group time">
<input class="form-control" type="text" value="" >
<span class="input-group-addon"><i class="fa fa-clock-o"></i></span>
</div>
Js
$('.time').datetimepicker({
format: 'LT'
}).on("dp.change",function(e){
var date = e.date;//e.date is a moment object
var target = $(e.target).attr('name');
console.log(date.format("HH:mm:ss"))//get time by using format
})
e.date is an instant object, so the time can be retrieved using the format ("HH: mm: ss")
+3
source to share