C#在Winform中显示当前日期、时间、星期

C#在Winform中显示当前日期、时间、星期

//加载窗体时
        string weekstr = "";
        private void Form22_Load(object sender, EventArgs e)
        {
            this.timer1.Start();  
            //把得到的星期转换成中文
            switch (DateTime.Now.DayOfWeek.ToString())
            {
                case "Monday": weekstr = "星期一"; break;
                case "Tuesday": weekstr = "星期二"; break;
                case "Wednesday": weekstr = "星期三"; break;
                case "Thursday": weekstr = "星期四"; break;
                case "Friday": weekstr = "星期五"; break;
                case "Saturday": weekstr = "星期六"; break;
                case "Sunday": weekstr = "星期日"; break;
            }
        }
 
        //定时器timer
        private void timer1_Tick(object sender, EventArgs e)
        {
             label2.Text = "当前时间:" + DateTime.Now.ToString() + " " + weekstr;
        }   
【注】拖控件timer在窗体,并设置Enable为true,Interval为10001秒)

转载链接:https://www.cnblogs.com/Mutual/p/5215945.html

你可能感兴趣的:(c#,开发语言,visual,studio)