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

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。