Search code examples
jquerydatetimepicker

Wrong time in maxDate


Hello I am using maxDate in datetimepicker like this:

const today = new Date()
$('#recordtime').datetimepicker({
   sideBySide: true,
   locale: 'bg',
   format: 'DD/MM/YYYY  HH:mm:ss',
   maxDate: today
});

But the problem is that I can pick till 8:00:00 - today enter image description here

Why is That? Do I need to set some local time settings in the script to restrict to 00:00:00?

The js that I use is: https://cdnjs.com/libraries/bootstrap-datetimepicker/4.17.37


Solution

  • The solution was to set the time to today.setHours(23,59,59,0) like @freedomn-m said and add timeZone as @phuzi wrote.

    const today = new Date()
    today.setHours(23,59,59,0)
    $('#recordtime').datetimepicker({
    locale: 'bg',
    format: 'DD/MM/YYYY  HH:mm:ss',
    timeZone: 'Europe/Sofia',
    maxDate: today
    });
    

    Thanks for the help in the comments and sorry for the wrong info that I wrote for the used js script...