使用ParseExact方法将字符串转换为日期格式

实现效果:

知识运用:

   DateTime结构的ParseExact方法

    public static DateTime ParseExact(string s,string format,IFormatProvider provider);

实现代码:

        private void button1_Click(object sender, EventArgs e)
        {
            string s = string.Format("{0}/{1}/{2}",     //得到日期字符串
                textBox1.Text, textBox2.Text, textBox3.Text);
            DateTime datetime = DateTime.ParseExact         //将字符串转换为日期格式
                (s,"yyyy/MM/dd",null);
           MessageBox.Show(datetime.ToLongDateString(),"转换结果");     //弹出消息对话框
        }

猜你喜欢

转载自www.cnblogs.com/feiyucha/p/9944004.html