使用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的格式和值一定要符合要求,不然異常  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM