使用Application_BeginRequest方法更改日期格式

时间:2013-11-03 08:06:45

标签: c#-4.0 datetime date-format

我想使用Application_BeginRequest方法更改所有系统的日期时间格式。 现在我正在使用这种方法

protected void Application_BeginRequest(object sender, EventArgs e)
    {
        CultureInfo newCulture = (CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
        newCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy hh:mm tt";

        Thread.CurrentThread.CurrentCulture = newCulture;

    }

我认为它应该显示像这样的日期时间格式“03/11/2013 01:59 AM”但实际上它看起来像这样“03/11/2013 01:59 AM 1:59:03 AM”。那是什么问题

1 个答案:

答案 0 :(得分:0)

我解决了问题,我正在使用以下方法

protected void Application_BeginRequest(object sender, EventArgs e)
    {
        CultureInfo newCulture = (CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();


        newCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
        newCulture.DateTimeFormat.LongTimePattern = "hh:mm tt";

        Thread.CurrentThread.CurrentCulture = newCulture;

    }
相关问题