I live in GMT+9, I want to input date and time that specified in my current time zone. Chrome Version 40.0.2214.93 (64-bit)
<input type="datetime-local" required>
However, if I input 12:00AM in the datetime picker,
the actual value that the element returns is 2015-01-30T00:00
(by printing out in the Chrome console), which equals 9:00AM in my time zone. Do I have to manually add 9 hours to the result? Since Chrome doesn't support datetime
as an input type, I cannot use datetime
as a replacement.
"2015-01-30T00:00" is exactly what you entered, so that is the result that is given back.
You said "... which equals 9:00AM in my time zone". That would only be true if the result was in UTC - which it is not. By the ISO8601 standard, it would only be presumed to be in UTC if the value ended with a trailing Z
, such as "2015-01-30T00:00Z".
Perhaps you are feeding the value into the Date
constructor?
new Date("2015-01-30T00:00")
In that case, the value will be interpreted as UTC - but that's due to a quirk of the Date
object. You can work around this with a bit of substitution:
new Date("2015-01-30T00:00".replace('T',' ').replace('-','/'))
Or, if you prefer cleaner code, consider using moment.js, which doesn't have that quirk:
moment("2015-01-30T00:00").toDate(); // or .format(), or other functions...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With