How to Get and Format Current Date in Javascript Appending It to Input
To add a current date in dd/mm/yyyy format to a hidden HTML input field, you can utilize Javascript. Follow these steps:
Example Code:
<code class="javascript">const today = new Date(); const yyyy = today.getFullYear(); let mm = today.getMonth() + 1; // Months start at 0! let dd = today.getDate(); if (dd < 10) dd = '0' + dd; if (mm < 10) mm = '0' + mm; const formattedToday = dd + '/' + mm + '/' + yyyy; document.getElementById('DATE').value = formattedToday;</code>
The above is the detailed content of How to Append the Current Date in dd/mm/yyyy Format to an Input Using Javascript?. For more information, please follow other related articles on the PHP Chinese website!