I am wondering whether it is possible to set the date format in the html <input type="date"></input>
tag... Currently it is yyyy-mm-dd, while I need it in the dd-mm-yyyy format.
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a way to play audio on a mobile browser w
- HTML form is not sending $_POST values
- implementing html5 drag and drop photos with knock
-
Why does the box-shadow property not apply to a
short direct answer is no or not out of the box but i have come up with a method to use a text box and pure JS code to simulate the date input and do any format you want, here is the code
1- please note that this method only work for browser that support date type.
2- the first function in JS code is for browser that don't support date type and set the look to a normal text input.
3- if you will use this code for multiple date inputs in your page please change the ID "xTime" of the text input in both function call and the input itself to something else and of course use the name of the input you want for the form submit.
4-on the second function you can use any format you want instead of day+" / "+month+" / "+year for example year+" / "+month+" / "+day and in the text input use a placeholder or value as yyyy / mm / dd for the user when the page load.
I found same question or related question on stackoverflow
I found one simple solution, You can not give particulate Format but you can customize Like this.
HTML Code:
CSS Code:
Javascript Code :
Output:
I made a lot of research and I don't think one can force format of the
<input type="date">
. The browser select the local format, and depending on user settings, if the user's language is in English, the date will be displayed to the English format (mm/dd/yyyy).In my opinion, the best solution is to use a plugin to control the display.
Jquery DatePicker seems a good option since you can force the localization, date format ...
Why not use the html5 date control as it is, with other attributes that allows it work ok on browsers that support date type and still works on other browsers like firefox that is yet to support date type
Clean implementation with no dependencies. https://jsfiddle.net/h3hqydxa/1/