0

做了一个custom datepickerwhich is in seperate dll,我希望它返回日期,dd/mm/yyyy format但它采用默认的美国文化,returning mm/dd/yyyy format我应该如何config culture为自定义日期选择器,以便不必单独转换每个页面中的格式。

4

2 回答 2

0

为所有页面设置 UI 文化和文化,在 Web.config 文件中添加一个全球化部分,然后设置 uiculture 和文化属性,如下例所示:

<globalization uiCulture="es" culture="es-MX" />

要为单个页面设置 UI 文化和文化,请设置 @Page 指令的 Culture 和 UICulture 属性,如下例所示:

<%@ Page UICulture="es" Culture="es-MX" %>

欲了解更多信息,请单击此处

于 2012-10-17T09:02:08.700 回答
0

您也可以使用此代码设置文化。

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
    // Creating a Global culture specific to our application.
    System.Globalization.CultureInfo cultureInfo = 
    new System.Globalization.CultureInfo("en-US");
    // Creating the DateTime Information specific to our application.
    System.Globalization.DateTimeFormatInfo dateTimeInfo = 
    new System.Globalization.DateTimeFormatInfo();
    // Defining various date and time formats.
    dateTimeInfo.DateSeparator = "/";
    dateTimeInfo.LongDatePattern = "dd-MMM-yyyy";
    dateTimeInfo.ShortDatePattern = "dd-MMM-yy";
    dateTimeInfo.LongTimePattern = "hh:mm:ss tt";
    dateTimeInfo.ShortTimePattern = "hh:mm tt";
    // Setting application wide date time format.
    cultureInfo.DateTimeFormat = dateTimeInfo;
    // Assigning our custom Culture to the application.
    Application.CurrentCulture = cultureInfo;
    Thread.CurrentThread.CurrentCulture = cultureInfo;
    Thread.CurrentThread.CurrentUICulture = cultureInfo;

    ..................
    Application.Run(new Form1());
}
于 2012-10-17T09:23:03.363 回答