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

前端 未结 15 1721
清酒与你
清酒与你 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: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("-");
        }
    
    

    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.

提交回复
热议问题