1

在我的 vb.Net 项目中,我使用下面的代码来设置 MyApplication 的日期格式

Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
        Dim newculture As System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture.Clone()
        newculture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy"
        newculture.DateTimeFormat.DateSeparator = "/"
        System.Threading.Thread.CurrentThread.CurrentCulture = newculture
End Sub

我如何在 c# 中做到这一点?

4

2 回答 2

2

Program.cs您拥有的文件中static void Main(),您可以在其中初始化应用程序设置。

    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        Application.CurrentCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
        Application.CurrentCulture.DateTimeFormat.DateSeparator = "/";

        Application.Run(new MainForm());
    }
于 2013-04-05T10:27:23.043 回答
-2

尝试在线转换器为您提供帮助,如下所示。

http://www.developerfusion.com/tools/convert/vb-to-csharp/

您的代码从相同转换而来。

private void MyApplication_Startup(object sender, Microsoft.VisualBasic.ApplicationServices.StartupEventArgs e)
{
    System.Globalization.CultureInfo newculture = System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
    newculture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
    newculture.DateTimeFormat.DateSeparator = "/";
    System.Threading.Thread.CurrentThread.CurrentCulture = newculture;
}
于 2013-04-05T10:28:41.110 回答