问题
I am using datetime-local
input
type in HTML, but I don't want to use the time portion. I want to only get the date.
<input type="datetime-local" name="book_date" id="book_date">
This is the output I get from the input
field:
2018-04-22T03:02
I want:
2018-04-22
Or how to remove the time portion from this value?
回答1:
If you only want the date portion, use type="date"
:
<input type="date" name="book_date" id="book_date"
onchange="console.log(this.value);" />
If you really want to use type="datetime-local"
, you can simply split the value by T
:
<input type="datetime-local" name="book_date" id="book_date"
onchange="console.log(this.value.split('T')[0]);" />
回答2:
You're looking for date
<input id="datetime" type="date" name="book_date" id="book_date">
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Form_%3Cinput%3E_types
来源:https://stackoverflow.com/questions/48919671/how-to-remove-time-value-in-datetime-local-input-type