JSFiddle - React, Tailwind, and code Playground
by musicreader
HTML
<input type="hidden" id="end" name="end" value="" />
<input type="date" id="endDate" name="endDate" />
JavaScript
// Convert the initial Unix timestamp to a date string and set the value of the date input
const initialTimestamp = 1725040275;
const initialDate = new Date(initialTimestamp * 1000).toISOString().split('T')[0];
document.getElementById('endDate').value = initialDate;
document.getElementById('end').value = initialTimestamp;
// Update the hidden input with the new timestamp whenever the date input changes
document.getElementById('endDate').addEventListener('change', function() {
const selectedDate = new Date(this.value);
const newTimestamp = Math.floor(selectedDate.getTime() / 1000);
alert(newTimestamp);
document.getElementById('end').value = newTimestamp;
});