HTML-5 date field shows as “mm/dd/yyyy” in Chrome, even when valid date is set

前端 未结 5 1225
慢半拍i
慢半拍i 2020-12-29 00:55

I just upgraded an ASP.Net MVC application to MVC-4. The field editor for inputs based on DateTime values now include\'s the HTML-5 type="date" attrib

5条回答
  •  一整个雨季
    2020-12-29 01:45

    I was having the same problem, with a value like 2016-08-8, then I solved adding a zero to have two digits days, and it works. Tested in chrome, firefox, and Edge

    today:function(){
       var today = new Date();
       var d = (today.getDate() < 10 ? '0' : '' )+ today.getDate();
       var m = ((today.getMonth() + 1) < 10 ? '0' :'') + (today.getMonth() + 1);
       var y = today.getFullYear();
       var x = String(y+"-"+m+"-"+d); 
       return x;
    }
    

提交回复
热议问题