c# 修改系统日期格式

 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         }

 

posted @ 2019-04-17 17:37  编程世界里晃荡  阅读(2215)  评论(0编辑  收藏  举报