Input[type="date"] returns wrong date via valueAsDate property. It is off by one day. For example: 2018-02-01 will be 2018-01-31 when accessed via valueAsDate property.
Reported by
aaronkl...@gmail.com,
Jan 10
|
|||
Issue descriptionUserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36 Steps to reproduce the problem: 1. Create input with type="date" set value="2018-02-01" 2. console.log(input.valueAsDate.toLocaleString()) 3. returns wrong date of 2018-01-31 instead of 2018-02-01 What is the expected behavior? valueAsDate should return the proper date that matches the input value. What went wrong? input.valueAsDate returns the wrong date. The date is off by one. Did this work before? N/A Does this work in other browsers? N/A Chrome version: 71.0.3578.98 Channel: stable OS Version: 10.0 Flash Version:
,
Jan 10
,
Jan 11
According to the HTML standard, valueAsDate returns a Date instance for 00:00 UTC of the value's date. So if your local timezone is later than UTC, toLocaleString() shows the previous date by default. You can show the expected date by adding { timeZone:'UTC' } argument to toLocaleString().
|
|||
►
Sign in to add a comment |
|||
Comment 1 by aaronkl...@gmail.com
, Jan 10