4 ms·
Better way to set this from input type=“date”: const el = /* get handle to date element */ const d = el.valueAsDate; d.setHours(0, 0, 0, 0); I won
by sangeeth96 1y ago
Better way to set this from input type=“date”:
const el = /* get handle to date element */
const d = el.valueAsDate;
d.setHours(0, 0, 0, 0);
I wonder why there’s no date-local like there’s datetime-local given this gotcha: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input/datetime-local https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/...
- cluckindan 1y agovalueAsDate: ”The date returned should always be interpreted as a UTC time” The setHours trick will probably not work as expected if the user is on a timezone with a positive UTC offset. They select a date in their local time, but in UTC, the date is still the previous day’s date! So when user selects 2025-07-30 in +09:00, the UTC datetime will be set to 2025-07-29T15:00:00Z. setHours will then make it 2025-07-29T00:00:00Z, the date part of which would be rendered in local time as 2025-07-29, a full day off from what the user intended.
- sangeeth96 1y agoAh, dang it! Thanks! Now that I read it, even *-local ones won’t do what I thought they did? valueAsDate isn’t a thing there. Wish I could unvote myself or that comment. Note to self: never comment on HN when you’re groggy and on a phone and never trust Date APIs lol. Can’t wait for Temporal to get here which hopefully irons these out better.