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

前端 未结 15 1718
清酒与你
清酒与你 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 04:52

    I know it's an old post but it come as first suggestion in google search, short answer no, recommended answer user a custom date piker , the correct answer that i use is using a text box to simulate the date input and do any format you want, here is the code

    
    
    date : 
    
        
    
    
      
    
    

    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.

提交回复
热议问题