1 [DllImport("kernel32.dll", EntryPoint = "GetSystemDefaultLCID")]
2 public static extern int GetSystemDefaultLCID();
3 [DllImport("kernel32.dll", EntryPoint = "SetLocaleInfoA")]
4 public static extern int SetLocaleInfo(int Locale, int LCType, string lpLCData);
5 public const int LOCALE_SLONGDATE = 0x20;
6 public const int LOCALE_SSHORTDATE = 0x1F;
7 public const int LOCALE_STIME = 0x1003;
8
9 public void SetDateTimeFormat()
10 {
11 try
12 {
13 int x = GetSystemDefaultLCID();
14 SetLocaleInfo(x, LOCALE_STIME, "HH:mm:ss"); //时间格式
15 SetLocaleInfo(x, LOCALE_SSHORTDATE, "yyyy-MM-dd"); //短日期格式
16 SetLocaleInfo(x, LOCALE_SLONGDATE, "yyyy-MM-dd"); //长日期格式
17 }
18 catch (Exception ex)
19 {
20 Console.WriteLine(ex);
21 }
22 }
2 public static extern int GetSystemDefaultLCID();
3 [DllImport("kernel32.dll", EntryPoint = "SetLocaleInfoA")]
4 public static extern int SetLocaleInfo(int Locale, int LCType, string lpLCData);
5 public const int LOCALE_SLONGDATE = 0x20;
6 public const int LOCALE_SSHORTDATE = 0x1F;
7 public const int LOCALE_STIME = 0x1003;
8
9 public void SetDateTimeFormat()
10 {
11 try
12 {
13 int x = GetSystemDefaultLCID();
14 SetLocaleInfo(x, LOCALE_STIME, "HH:mm:ss"); //时间格式
15 SetLocaleInfo(x, LOCALE_SSHORTDATE, "yyyy-MM-dd"); //短日期格式
16 SetLocaleInfo(x, LOCALE_SLONGDATE, "yyyy-MM-dd"); //长日期格式
17 }
18 catch (Exception ex)
19 {
20 Console.WriteLine(ex);
21 }
22 }