码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-11-14 00:57:42      阅读:431      评论:0      收藏:0      [点我收藏+]

标签:long   image   message   void   box   send   text   运用   class   

实现效果:

技术分享图片技术分享图片

知识运用:

   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方法转换日期显示格式

标签:long   image   message   void   box   send   text   运用   class   

原文地址:https://www.cnblogs.com/feiyucha/p/9955623.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!