Winfrom 设置PC 端日期格式

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace ZB.QueueSys.Common
{
    public class DateHelper
    {
        private static DateHelper instance;
        public static DateHelper Instance
        {
            get
            {
                if (instance == null) instance = new DateHelper();
                return DateHelper.instance;
            }
        }


        [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 { return; }
        }

    }
}

  

Winfrom 设置PC 端日期格式

上一篇:WPF 饼状图,柱形图,折线图 (2 折线图)


下一篇:[WPF 学习] 14.PlaceHolder的简单实现