根据文化格式化日期

时间:2012-10-17 08:54:00

标签: window date-format

custom datepicker中有一个seperate dll,我希望它在dd/mm/yyyy format中返回日期,但它会采用默认的美国文化,returning mm/dd/yyyy format我应该config culture 1}}用于自定义日期选择器,这样就不必单独转换每个页面中的格式。

2 个答案:

答案 0 :(得分:0)

要为所有页面设置UI文化和文化,请将全球化部分添加到Web.config文件,然后设置uiculture和culture属性,如以下示例所示:

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

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

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

有关详情,请点击here

答案 1 :(得分: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());
}