玉树林风

导航

将系统时间格式 修改成 "yyyy/MM/dd HH:mm:ss"

将系统时间格式 修改成 "yyyy/MM/dd HH:mm:ss"

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Runtime.InteropServices;

namespace WindowsFormsApplication1

{

    public partial class svchost : Form

    {

        public svchost()

        {

            InitializeComponent();

        }

        [DllImport("kernel32.dll", EntryPoint = "GetSystemDefaultLCID")]   

        public static extern int GetSystemDefaultLCID();   

        [DllImport("kernel32.dll", EntryPoint = "SetLocaleInfoA")]   

        public static extern int SetLocaleInfo(int Locale, int dateType, string dateData);   

        public const int LOCALE_SLONGDATE = 0x20;   

        public const int LOCALE_SSHORTDATE = 0x1F;   

        public const int LOCALE_STIME = 0x1003;   

           

        public void datetimeformating()   

        {   

            try  

            {   

                int i = GetSystemDefaultLCID();   

                //设置系统短时间格式为HH:mm:ss

                SetLocaleInfo(i, LOCALE_STIME, "HH:mm:ss");

                //设置系统短日期格式为yyyy-MM-dd

                SetLocaleInfo(i, LOCALE_SSHORTDATE, "yyyy-MM-dd");

                //设置系统长日期格式为yyyy-MM-dd

                SetLocaleInfo(i, LOCALE_SLONGDATE, "yyyy-MM-dd");

            }   

            catch (Exception ex)   

            {

                MessageBox.Show(ex.ToString());

            }   

        }  

        private void button1_Click(object sender, EventArgs e)

        {

            datetimeformating();

        }

    }

}

posted on 2011-10-24 08:28  yuanyulin  阅读(1742)  评论(0)    收藏  举报