DateTime startTime = DateTime.Now; DateTime endTime = DateTime.Now.AddSeconds( 75 ); TimeSpan span = endTime.Subtract ( startTime ); Console.WriteLine( "Time Difference (seconds): " + span.Seconds ); Console.WriteLine( "Time Difference (minutes): " + span.Minutes ); Console.WriteLine( "Time Difference (hours): " + span.Hours ); Console.WriteLine( "Time Difference (days): " + span.Days );
//เปลี่ยน format เป็น time ด้วยนะครับ //this.dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Time; this.Text = new DateTime((dateTimePicker2.Value - dateTimePicker1.Value).Ticks).ToString("hh:mm:ss");
this.dateTimePicker1.CustomFormat = "hh:mm:ss tt"; this.dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
// dateTimePicker1 // //this.dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Time; this.Text = new System.DateTime((dateTimePicker2.Value - dateTimePicker1.Value).Ticks).ToString("hh:mm:ss"); this.dateTimePicker1.Location = new System.Drawing.Point(39, 40); this.dateTimePicker1.Name = "dateTimePicker1"; this.dateTimePicker1.Size = new System.Drawing.Size(108, 20); this.dateTimePicker1.TabIndex = 127;
public partial class Form1 : Form { public Form1() { InitializeComponent(); this.dateTimePicker1.CustomFormat = "hh:mm:ss tt"; this.dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom; this.dateTimePicker2.CustomFormat = "hh:mm:ss tt"; this.dateTimePicker2.Format = System.Windows.Forms.DateTimePickerFormat.Custom; } private void button1_Click(object sender, EventArgs e) { TimeSpan t = dateTimePicker1.Value - dateTimePicker2.Value; DateTime d1 = dateTimePicker1.Value; DateTime d2 = dateTimePicker2.Value; richTextBox1.Text += Environment.NewLine + "dateTimePicker2.Value - dateTimePicker1.Value = " + d2.ToString() + "-" + d1.ToString() + "= " + (dateTimePicker2.Value - dateTimePicker1.Value); richTextBox1.Text += Environment.NewLine; richTextBox1.Text += Environment.NewLine + "dateTimePicker1.Value - dateTimePicker2.Value = " + d1.ToString() + "-" + d2.ToString() + "= " + (dateTimePicker1.Value - dateTimePicker2.Value); this.Text = new DateTime(System.Math.Abs((dateTimePicker1.Value - dateTimePicker2.Value).Ticks)).ToString("hh:mm:ss"); } }
dateTimePicker1.Value - dateTimePicker2.Value หรือ dateTimePicker2.Value - dateTimePicker1.Value
string d1 = DateTime.Now.ToShortDateString(); string d2 = DateTime.Now.ToShortDateString(); d1 = d1 + " 01:20:10"; d2 = d2 + " 23:50:59"; dateTimePicker1.Value = DateTime.Parse(d1); dateTimePicker2.Value = DateTime.Parse(d2); DateTime date1 = dateTimePicker1.Value; DateTime date2 = dateTimePicker2.Value; private void button1_Click(object sender, EventArgs e) { TimeSpan ts = dateTimePicker2.Value - dateTimePicker1.Value; this.Text = new DateTime(ts.Ticks).ToString("HH:mm:ss"); }
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง