当前位置: 移动技术网 > IT编程>开发语言>c# > C# 设置系统日期格式的方法

C# 设置系统日期格式的方法

2019年07月18日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:[dllimport("kernel32.dll", entrypoint = "getsystemdefaultlcid")]  

复制代码 代码如下:

[dllimport("kernel32.dll", entrypoint = "getsystemdefaultlcid")]
        public static extern int getsystemdefaultlcid();
        [dllimport("kernel32.dll", entrypoint = "setlocaleinfoa")]
        public static extern int setlocaleinfo(int locale, int lctype, string lplcdata);
        public const int locale_slongdate = 0x20;
        public const int locale_sshortdate = 0x1f;
        public const int locale_stime = 0x1003;

        public void setdatetimeformat()
        {
            try
            {
                int x = getsystemdefaultlcid();
                setlocaleinfo(x, locale_stime, "hh:mm:ss");        //时间格式 
                setlocaleinfo(x, locale_sshortdate, "yyyy-mm-dd");   //短日期格式   
                setlocaleinfo(x, locale_slongdate, "yyyy-mm-dd");   //长日期格式  
            }
            catch (exception ex)
            {
                console.writeline(ex);
            }
        } 

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网