Jquery 日期选择器日期时间格式问题。如果更改本地系统日期格式,行为将发生变化
我是MVC3的新手,为公司做评估工作。今天,我一直在使用MVC3中的日期格式 我有一个具有以下方法的模型类Jquery 日期选择器日期时间格式问题。如果更改本地系统日期格式,行为将发生变化,jquery,asp.net-mvc-3,Jquery,Asp.net Mvc 3,我是MVC3的新手,为公司做评估工作。今天,我一直在使用MVC3中的日期格式 我有一个具有以下方法的模型类 [DataType(DataType.Date)] [Display(Name = "Date Of Birth")] [DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}", ApplyFormatInEditMode = true)] public DateTime? DOB { get; set; } [DataType(DataTy
[DataType(DataType.Date)]
[Display(Name = "Date Of Birth")]
[DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}", ApplyFormatInEditMode = true)]
public DateTime? DOB { get; set; }
[DataType(DataType.Date)]
[Display(Name = "Date Of Joining")]
[DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}", ApplyFormatInEditMode = true)]
public DateTime? DOJ { get; set; }
在我看来,我调用了jquery内置函数Datepicker
<script language="javascript" type="text/javascript">
$(function () {
$("#DOB").datepicker({
changeMonth: true,
changeYear: true,
yearRange: "1942:2099",
dateFormat: 'dd/mm/yy'
});
$("#DOJ").datepicker({
changeMonth: true,
changeYear: true,
yearRange: "2010:2099",
dateFormat: 'dd/mm/yy'
});
});
</script>
$(函数(){
$(“#DOB”).日期选择器({
变化月:对,
变化年:是的,
年份范围:“1942:2099”,
日期格式:“日/月/年”
});
美元(“#DOJ”)。日期选择器({
变化月:对,
变化年:是的,
年份范围:“2010:2099”,
日期格式:“日/月/年”
});
});
如果我的本地系统日期格式为“dd-mm-yyyy”格式,则此代码工作正常,但如果我在本地系统中更改任何其他格式的日期格式,则开始抛出错误
这里我的问题是,如何使它成为通用日期时间格式,以便在部署后不会抛出错误 听起来问题与文化背景有关。我在日期格式方面也遇到了类似的问题,我通过在web.config的
部分添加这些行来解决它
<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="en-GB" uiCulture="en-GB"/>
希望能有帮助