I have here a script to auto-input the current date on my input tag. However, I cannot add an auto timestamp like date.getHour();
as well. It's not working when I tried doing this.
Please take a look at the script I'm using:
var date = new Date();
var day = date.getDate();
var month = date.getMonth() + 1;
var year = date.getFullYear();
if (month < 10) month = "0" + month;
if (day < 10) day = "0" + day;
var today = year + "-" + month + "-" + day;
document.getElementById('Date').value = today;
<form id="saveNote">
<textarea class="lined" id="textarea1" name="textarea1" spellcheck="true" placeholder="" onpaste="console.log('onpastefromhtml')"></textarea>
<input type="date" id="Date" name="Date"/>
</form>
<button onclick="save()">Submit</button>
All I'm looking for is a simple solution that will add a timestamp at the end of the day like "1/12/2021 - 02:00 PM" or even in 24-hour format.
EDIT: Here's my failed code:
var date = new Date();
var day = date.getDate();
var month = date.getMonth() + 1;
var year = date.getFullYear();
var hour = date.getHours()
if (month < 10) month = "0" + month;
if (day < 10) day = "0" + day;
var today = year + "-" + month + "-" + day + "-" + hour;
document.getElementById('Date').value = today;
Thanks in advance!