实现效果:

使用ToDateTime方法转换日期显示格式使用ToDateTime方法转换日期显示格式

知识运用:

   Convert类的ToDateTime方法:(将字符串转化为DateTime对象)

    public static DateTime ToDateTime(string value)  //value: 字符串对象,日期和时间的字符串表形式

实现代码:

 1         private void button1_Click(object sender, EventArgs e)
 2         {
 3             if (textBox1.Text != string.Empty &&
 4                 textBox2.Text != string.Empty &&
 5                 textBox3.Text != string.Empty)
 6             {
 7                 string s = string.Format("{0}/{1}/{2}", //得到日期字符串
 8                     textBox1.Text, textBox2.Text, textBox3.Text);
 9                 MessageBox.Show("输入的日期为:"+           //显示消息对话框
10                     Convert.ToDateTime(s).ToLongDateString());
11             }
12             else { MessageBox.Show("没有输入完整,请检查"); }
13         }

 

注意补充:

  value的格式和值一定要符合要求,不然异常  

使用ToDateTime方法转换日期显示格式

 

相关文章:

  • 2021-07-10
  • 2021-12-22
  • 2021-11-25
  • 2021-06-06
  • 2021-05-27
  • 2022-01-30
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-07
  • 2021-12-22
  • 2022-02-19
  • 2021-09-26
相关资源
相似解决方案