How to remove time value in datetime-local input type?

偶尔善良 提交于 2019-12-24 08:29:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!