C#獲取和更改Windows當(dāng)前日期時(shí)間
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
C#得到Windows當(dāng)前日期時(shí)間,演示獲取和設(shè)置系統(tǒng)日期時(shí)間,程序還可設(shè)置系統(tǒng)當(dāng)前日期時(shí)間,相信你一看就會(huì)明白了,程序運(yùn)行界面如截圖所示。
{//獲取當(dāng)前系統(tǒng)日期時(shí)間 DateTimePicker OlddateTimePicker = new DateTimePicker(); this.textBox1.Text=OlddateTimePicker.Value.ToLongDateString().ToString(); this.textBox1.Text+=OlddateTimePicker.Value.ToLongTimeString().ToString(); //設(shè)置系統(tǒng)當(dāng)前日期時(shí)間 if(MessageBox.Show("您真的確定更改系統(tǒng)當(dāng)前日期時(shí)間嗎?","信息提示",MessageBoxButtons.OK)==DialogResult.OK) { DateTime Year=this.dateTimePicker1.Value; SystemTime MySystemTime = new SystemTime(); LibWrapDateTime.GetLocalTime(MySystemTime); MySystemTime.wYear=(ushort)this.dateTimePicker1.Value.Year; MySystemTime.wMonth=(ushort)this.dateTimePicker1.Value.Month; MySystemTime.wDay=(ushort)this.dateTimePicker1.Value.Day; MySystemTime.wHour=(ushort)this.dateTimePicker2.Value.Hour; MySystemTime.wMinute=(ushort)this.dateTimePicker2.Value.Minute; MySystemTime.wSecond=(ushort)this.dateTimePicker2.Value.Second; LibWrapDateTime.SetLocalTime(MySystemTime); button1_Click(null,null); } 該文章在 2021/2/4 11:17:03 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |