Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

183
Visualizações
Set hour and minute on day select using jquery datetimepicker plugin

I'm trying to set time using variables using jquery datetimepicker. So the problem is the following: in my logic i've datetimepicker that can select date and time. When the user click on form field and select date only, the plugin set selected date and current time. But we have different time available set by code (for example: monday 9:00 to 12:00 (step 1 hour), tuesday 8:00 to 11:00). So the picker doesn't have to set the current time but the first time available, for example 9:00 for monday.

When i select date only, it set also the time (but is wrong because in this case we have only 9:00 in the morning), so the result should be: 2022/04/01 09:00

this is when i select day

How can i set it up? Below some code example:

Datetimepicker(jquery):

/**
 * @param currentDateTime {Date}
 */
const allowTimeOnSelectedDay = function (currentDateTime) {
    if (currentDateTime != null) {
        var currentDay = currentDateTime.getDay();
        const map1 = data.week.map(el => {
            if (el.day == currentDay) {

                let allowedTimes = generateAllowedTime(el.startingMattina, el.closingMattina, el.startingPome, el.closingPome);
                console.log(allowedTimes);
                console.log(allowedTimes[0]);
                this.setOptions({
                    allowTimes: allowedTimes
                });
            }
        });
    }
};

$('#datetimepicker11').datetimepicker({
    dayOfWeekStart: 1,
    formatDate: 'd/m/Y H:i',
    minDate: dateToStart,
    maxDate: new Date(Date.parse(data.endDate)),
    startDate: dateToStart,
    beforeShowDay: function (date) {

        for (let i = 0; i < arr.length; i++) {
            if (date.getMonth() == arr[i].getMonth() && date.getDate() == arr[i].getDate()) {
                return [false, ""]
            }
        }
        return [true, ""];
    },
    onChangeDateTime: allowTimeOnSelectedDay,
    onShow: allowTimeOnSelectedDay,
    //onSelectDate : formattedDateOnSelectedDateOnly,

});
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda