I pass the date in the text field using js, but the date is transmitted in the form 12/04/2018, but on 12/04/2018, tell me how to fix it, I do this:

var dsec = new Date(); var mm = dsec.getMonth() + 1; $('#inputDateSecond').val(dsec.getDate() + "." + mm + "." + dsec.getFullYear()); 

    1 answer 1

     var dsec = new Date(); var mm = dsec.getMonth() + 1; var dt = dsec.getDate(); if (dt < 10) dt = '0' + dt; $('#inputDateSecond').val(dt + "." + mm + "." + dsec.getFullYear()); 
    • swears Invalid left hand side for assignment if (dsec.getDate() < 10) d - Sorpok
    • everything works for me jsfiddle.net/5r6wntsL - boneskhv
    • If I do this var dsec = new Date(); var mm = dsec.getMonth() + 1; if (dsec <= 10) dsec = '0' + dsec; $('#inputDateSecond').val(dsec + "." + mm + "." + dsec.getFullYear()); var dsec = new Date(); var mm = dsec.getMonth() + 1; if (dsec <= 10) dsec = '0' + dsec; $('#inputDateSecond').val(dsec + "." + mm + "." + dsec.getFullYear()); then the date of this type Tue Dec 04 2018 10:02:37 - Sorpok
    • follow the link in jsfiddle (though I changed the code in my answer), which I gave above. there is exactly your case and in the input the date is normally inserted in the format 04.12.2018. Also, do not make a comparison <=, otherwise your 10th number will be displayed as '010' - boneskhv
    • then I just commented one line, and where <= I wanted to put 9) thanks a lot !!! - Sorpok