Is there any way to change input type=“date” format?

前端 未结 15 1777
清酒与你
清酒与你 2020-11-21 04:17

I\'m working with HTML5 elements on my webpage. By default input type=\"date\" shows date as YYYY-MM-DD.

The question is, is it possible t

相关标签:
15条回答
  • 2020-11-21 05:07

    I searched this issue 2 years ago, and my google searches leads me again to this question. Don't waste your time trying to handle this with pure JavaScript. I waste my time trying to make it dd/mm/yyyy. There's no complete solutions that fits with all browsers. So I recommend to use jQuery datepicker or tell your client to work with the default date format instead

    0 讨论(0)
  • 2020-11-21 05:08

    It's not possible to change web-kit browsers use user's computer or mobiles default date format. But if you can use jquery and jquery UI there is a date-picker which is designable and can be shown in any format as the developer wants. the link to the jquery UI date-picker is on this page http://jqueryui.com/datepicker/ you can find demo as well as code and documentation or documentation link

    Edit:-I find that chrome uses language settings that are by default equal to system settings but the user can change them but developer can't force users to do so so you have to use other js solutions like I tell you can search the web with queries like javascript date-pickers or jquery date-picker

    0 讨论(0)
  • 2020-11-21 05:08

    Since the post is active 2 Months ago. so I thought to give my input as well.

    In my case i recieve date from a card reader which comes in dd/mm/yyyy format.

    what i do. E.g.

    var d="16/09/2019" // date received from card
    function filldate(){
        document.getElementById('cardexpirydate').value=d.split('/').reverse().join("-");
        }
    <input type="date" id="cardexpirydate">
    <br /><br />
    <input type="button" value="fill the date" onclick="filldate();">

    what the code do:

    1. it splits the date which i get as dd/mm/yyyy (using split()) on basis of "/" and makes an array,
    2. it then reverse the array (using reverse()) since the date input supports the reverse of what i get.
    3. then it joins (using join())the array to a string according the format required by the input field

    All this is done in a single line.

    i thought this will help some one so i wrote this.

    0 讨论(0)
提交回复
热议问题