One of the nice features in HTML5 is the abililty khổng lồ specify a specific input đầu vào type for HTML text đầu vào boxes. There a host of very useful input types available including gmail, number, date, datetime, month, number, range, tìm kiếm, tel, time, url & week. For a more complete danh mục you can check out the MDoanh Nghiệp reference. Date input đầu vào types also support automatic validation which can be useful in some scenarquả táo but maybe can get in the way at other times.
Bạn đang xem: Is there any input date format mm
One of the more common input đầu vào types, và one that can most benefit of a custom UI for selection is of course date đầu vào. Almost every application could use a decent date representation and HTML5"s date input đầu vào type seems khổng lồ push into lớn the right direction. It"d be nice if you could just say:
Problem #1: Browser Support
For starters there"s browser tư vấn. Out of the major browsers only the lakiểm tra versions of WebKit & Opera based browsers seem to tư vấn date input đầu vào. Neither FireFox, nor any version of Internet Explorer (including the new touch enabled IE10 in Windows RT) tư vấn input đầu vào type=date. Browser tư vấn is an issue, but it would be OK if it wasn"t for problem #2.
Problem #2: Date Formatting
If you look at my date input from before:
Chrome isn"t recognizing my local date string. Instead it"s expecting my date format lớn be provided in ISO 8601 format which is:
So if I change the date input field to:
và then save sầu, the value field is phối bachồng to:
using the ISO format. The same is true for Opera and iOS browsers và I suspect any other WebKit style browser and their date pickers.
So lớn summarize đầu vào type=date:Expects ISO 8601 format dates to lớn display intial valuesSets selected date values lớn ISO 8601
This would sort of make sense, if all browsers supported input type=date. It"d be easy because you could just format dates appropriately when you mix the date value inkhổng lồ the control by applying the appropriate culture formatting (ie. .ToString("yyyy-MM-dd") ). .NET is actually smart enough to piông xã up the date on the other over for modelbinding when ISO 8601 is used. For other environments this might be a bit more tricky.
đầu vào type=date is clearly the way to go forward. Date controls implemented in HTML are going the way of the dovì chưng, given the intricacies of di động platforms và scaling for both desktop & mobile. I"ve sầu been using jQuery UI Datepicker for ages but once going to lớn điện thoại, that"s no longer an option as the control doesn"t scale down well for Mobile apps (at least not without major re-styling). It also makes a lot of sense for the browser to lớn provide this functionality - creating a consistent date input đầu vào experience across apps only makes sense, which is why I find it baffling that neither FireFox nor IE 10 deign it necessary khổng lồ support date đầu vào natively.
The problem is that a large number of even the lakiểm tra and greatest browsers don"t tư vấn this. So now you"re stuck with not knowing what date format you have sầu to serve since neither the local format, nor the ISO format works in all cases.
It"s possible lớn check for the availability of đầu vào types with Modernizr by checking:
for true or false. Unfortunately this is a client side thing, which means you"d have to lớn delay formatting your date on the client using some sort of client library for date formatting lượt thích Moment.js rather than pushing a date inkhổng lồ the UI from the hệ thống. This would work for a client heavy application that"s using client side templates to render nội dung, but not so well for a typical HTML server rendered ứng dụng.
For my current app I just broke down and used the ISO format & so I"ll live sầu with the non-local date format.
Here"s what it looks like on my iPhone:
Both Chrome & the phone vày this the way it should be. The iPhone date display và date picker in particular are very nice (better than anything on the desktop - that"s for sure) and it demonstrates why we"d want this implemented in the browser to tóm tắt this common UI for any application that provides date đầu vào. The iOS built-in date picker there certainly beats manually trying khổng lồ edit the date using finger gymnastics.
Finally here"s what the date looks like in FireFox which doesn"t support date input types:
Certainly this is not the ideal date format, but it"s clear enough I suppose. If users enter a date in local US format and that works as well (but won"t work for other locales). It"ll have to bởi vì.
Over time one can only hope that other browsers will finally decide to lớn implement this functionality natively to provide a unique experience. Until then, incomplete solutions it is.