HTML <input type='date'> Not Formatting Correctly in Chrome on macOS - Timezone Issues
I'm optimizing some code but I'm working with an scenario with the `<input type='date'>` element in my HTML form. When I select a date in Chrome on macOS, it seems to be outputting the date in UTC rather than the local timezone, which is causing problems when I try to submit the form. For example, if I select '2023-10-10' in the date picker, the value submitted is '2023-10-10T00:00:00Z'. Iโve tried using JavaScript to convert the date to local time before submission, but I need to seem to get it right. Hereโs the code snippet Iโm using: ```html <form id="myForm"> <label for="dateInput">Choose a date:</label> <input type="date" id="dateInput" name="dateInput"> <input type="submit" value="Submit"> </form> <script> document.getElementById('myForm').onsubmit = function() { const dateInput = document.getElementById('dateInput').value; const localDate = new Date(dateInput + 'T00:00:00'); console.log(localDate.toString()); // add code here to format and submit the date correctly }; </script> ``` Iโve also tried setting the timezone manually using `Intl.DateTimeFormat` but that didnโt yield the expected results either. The date still appears in UTC on the server side. Is there a reliable way to ensure the date is submitted in the local timezone? Any insights or workarounds would be greatly appreciated! I've been using Html for about a year now.