jqueryui datepicker dd/MM/yy文化相关问题 [英] jqueryui datepicker dd/MM/yy culture related issue
问题描述
我正在将 jQueryUI datepicker 用于简单的发件人&我的ASP.Net MVC网络应用中的到"日期范围过滤器.在我将日期时间格式(在区域设置"中)设置为"dd-MM-yy"的机器上运行正常.
I'm using a jQueryUI datepicker for a simple "From" & "To" date range filter in my ASP.Net MVC web-app. Works fine until I hit a machine which had its datetime format (in the Regional Settings) set to "dd-MM-yy".
在我的控制器中,我有一个回发操作,该操作接受自定义搜索对象作为参数,然后将其传递给搜索功能.此自定义对象的属性为"To"和&". 起始"日期和往常一样,绑定是自动进行的.在日期格式为"MM/dd/yy"的计算机上可以正常工作,但是如果我在区域设置中将其设置为"dd/MM/yy",则无法解析日期.
In my controller I've a postback action which accepts a custom search object as a parameter which is then passed to the search function. This custom object has the properties for "To" & "From" dates and as usual the binding takes place automatically. Works normal on a machine with date format "MM/dd/yy" but if I set it to "dd/MM/yy" in the regional settings then it is unable to parse the date.
最简单的解决方案是将datepicker的格式更改为 "dd-MMM-yyyy"(非文化专用的日期格式),但是我的客户想要 所选日期以MM/dd/yyyy格式显示.
The easiest solution could be to change the datepicker's format to "dd-MMM-yyyy" a non-culture specific date format but my client wants the selected date to be displayed in MM/dd/yyyy format.
是否有任何简单易用的建议在日期选择器或控制器级别处理此问题?
Any clean and easy suggestion to handle this at the datepicker or controller level?
推荐答案
您可以使用具有自定义格式的隐藏字段:
You can use an hidden field with a custom format:
HTML:
<input name="from" type="text" id="from" />
<input name="hiddenFrom" type="hidden" id="hiddenFrom" />
JavaScript:
Javascript:
$("#from").datepicker({
altField: "#hiddenFrom",
altFormat: "dd-mm-yy" // or whatever
});
您会在此处
这篇关于jqueryui datepicker dd/MM/yy文化相关问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!