javascriptparsingdatetimepickerbootstrap-datetimepicker

How can I convert the value I get with datetimepicker to date and time?


var innerDate = document.getElementById('datetimepicker3').value;

The format I get from this line is: innerDate: "2021/07/07 14:00"

But I need to parse the date and time information here. How can I convert Start Date and Start Time into two separate variables?


Solution

  • Try this:

    var innerDate = new Date(document.getElementById('datetimepicker3').value)
    

    Or you can attach an event handler to get the date whenever it changes

    <script type="text/javascript">
       $("#datetimepicker3").on("dp.change", function (e) {
            let date = e.date;
            console.log(date);
            // no need to convert to a date
       });
    </script>