I am trying to set the date with a formatted date but I don't know how to do that can you please help me to do it. the default i get is "17/11/201" but i want "Nov 17, 20021" and how to disable past dates with this code thank you so much for helping me
const input = document.createElement('input');
input.type = "date"
input.id = "scheduleTime"
input.className = "input-text";
input.value = new Date(Date.now()).toLocaleDateString('en-CA');
CodePudding user response:
new Date(Date.now()).toLocaleString('en-Ca', { month: 'short', day: 'numeric', year: 'numeric' });
More info is there. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString
CodePudding user response:
If it was me i would use the moment.js library
It allows you to do the following:
moment().format('MMM DD, YYYY')
As apposed to the native solution, which would be something along the lines of:
new Date(Date.now()).toLocaleString('en-CA', { month: 'short', day: 'numeric', year: 'numeric' });