我有一个带有 EF 项目的 ASP.NET MVC 4。当用户登录时,我正在更改当前的线程文化。 Global.asax.cs
protected void Application_BeginRequest(object sender, EventArgs e)
{
CultureInfo objculture = new CultureInfo(Helios.MvcApplication.Lang); //Lang = en-US, ro-RO, fr-FR
//DateTimeFormatInfo objDTFI = objculture.DateTimeFormat;
//objDTFI.ShortDatePattern = "dd.MM.YY";
//objDTFI.DateSeparator = ".";
//objculture.DateTimeFormat = objDTFI;
objculture.NumberFormat.CurrencyDecimalSeparator = ".";
objculture.NumberFormat.NumberDecimalSeparator = ".";
Thread.CurrentThread.CurrentUICulture = objculture;
Thread.CurrentThread.CurrentCulture = objculture;
}
DateTime.cshtml //我的日期时间的EditorTemplate
@model System.DateTime?
@Html.TextBox("", String.Format("{0:d}", Model.HasValue ? Model : DateTime.Today), new { @class = "datefield" })
<link rel="stylesheet" href="http://code.jquery.com/ui/1.8.20/themes/base/jquery-ui.css" type="text/css" media="all" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.8.20/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$(".datefield").datepicker({
changeMonth: true, changeYear: true, firstDay: 1, changeYear: true,
dateFormat: 'dd.mm.yy'
});
});
如果我使用:String.Format("{0:yyyy-MM-dd}"或String.Format("{0:MM-dd-yyyy}"它可以工作,但如果我使用String.Format("{0: dd.MM.yyyy}"它不起作用。
问:如何将每种文化/语言的日期时间格式更改为“dd.MM.yyyy” ?