【发布时间】:2016-01-03 03:40:21
【问题描述】:
我已经根据客户区域转换了日期时间格式。 我已经使用 c# 完成了下面的代码
public CultureInfo GetDateFormat()
{
var _CultureInfo = new CultureInfo(1043);
return _CultureInfo;
}
public string GetFormattedDateString(string _DateToFormat)
{
string _tempDate = string.Empty;
if (!string.IsNullOrEmpty(_DateToFormat))
{
_tempDate = DateTime.Parse(_DateToFormat).ToString(GetDateFormat().DateTimeFormat.ShortDatePattern);
}
return _tempDate;
}
这很好用。但是如果我在 jQuery datepicker 中使用相同的方法,它会给出不同的格式。
例如:在c#
2015 年 10 月 10 日
在jquery
2015 年 10 月 10 日
下面是jQuery格式改变的代码,
public string GetDateFormat()
{
var pattern = new CultureInfo(1043).DateTimeFormat.ShortDatePattern;
return pattern;
}
@Html.DatePicker(new {
name = "filter.StartDate",
value = Model.Filter.StartDate,
data_bind = "value: StartDate",
data_datepicker_options = "{dateFormat: '" + GetDateFormat() + "'}"
})
上面是创建日期选择器的剃须刀代码。
有没有办法在 c# 和 datepicker 输出中获得相同的日期格式?
【问题讨论】:
-
你试过显式
dateFormat: 'dd-mm-yy'吗?
标签: c# jquery datetime datepicker cultureinfo