用C#代码修改区域与语言的短日期格式
2011-08-08 11:44
429 查看
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 }
相关文章推荐
- Oracle EBS Reports 日期格式 与 客户端日期格式(控制面板 > 区域和语言选项)
- c# 利用Window API函数修改计算机日期时间和格式
- C#获得自己想要设定不依赖于区域的日期格式
- WIN API-VFP更改Windows的区域选项:(长)日期格式(分隔符),时间格式(分隔符)[参考:控制面板-区域和语言选项-区域选项]
- c# 修改系统日期格式
- C#语言之“string格式的日期时间字符串转为DateTime类型”的方法
- 修改某语言环境下默认日期的格式
- C#语言之“string格式的日期时间字符串转为DateTime类型”的方法
- 【转】C#语言之“string格式的日期时间字符串转为DateTime类型”的方法
- C#语言之“string格式的日期时间字符串转为DateTime类型”的方法
- C#中获取日期之间天数的方法代码,及DataTime方法的日期格式整理
- C#语言之“string格式的日期时间字符串转为DateTime类型”的方法
- C#语言之“string格式的日期时间字符串转为DateTime类型”的方法
- C#语言之“string格式的日期时间字符串转为DateTime类型”的方法
- 用C#修改系统区域和语言设置
- (转载)C#语言之“string格式的日期时间字符串转为DateTime类型”的方法
- (转载)C#语言之“string格式的日期时间字符串转为DateTime类型”的方法
- c# Eval函数中将日期显示的格式修改为yyyy-MM-dd形式
- C#语言之“string格式的日期时间字符串转为DateTime类型”的方法
- C#语言之“string格式的日期时间字符串转为DateTime类型”的方法