亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 編程 > C# > 正文

C#實現修改系統時間的方法

2020-01-24 02:37:49
字體:
來源:轉載
供稿:網友

本文所述C#獲取和修改系統時間的實現步驟為:系統的時間從 SystemTime 結構體中取出,并顯示在textBox1上,從setDate,setTime控件中獲取年,月,日,小時,分鐘,秒信息,存入SystemTime結構體中,然后使用SetLocalTime(ref systemTime)設置為用戶指定的時間。本代碼編譯后會有一個易于操作的窗體。

完整功能代碼如下:

using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.Runtime.InteropServices;namespace changesystime{ /// <summary> /// Form1 的摘要說明。 /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Timers.Timer timer1; private System.Windows.Forms.DateTimePicker setDate; private System.Windows.Forms.DateTimePicker setTime; private System.ComponentModel.IContainer components; [StructLayout(LayoutKind.Sequential)] public struct SystemTime {  public ushort wYear;  public ushort wMonth;  public ushort wDayOfWeek;  public ushort wDay;  public ushort wHour;  public ushort wMinute;  public ushort wSecond;  public ushort wMiliseconds; }  // 用于設置系統時間 [DllImport("Kernel32.dll")] public static extern bool SetLocalTime( ref SystemTime sysTime ); // 用于獲得系統時間 [DllImport("Kernel32.dll")] public static extern void GetLocalTime(ref SystemTime sysTime); public Form1() {  //  // Windows 窗體設計器支持所必需的  //  InitializeComponent();  //  // TODO: 在 InitializeComponent 調用后添加任何構造函數代碼  // } /// <summary> /// 清理所有正在使用的資源。 /// </summary> protected override void Dispose( bool disposing ) {  if( disposing )  {  if (components != null)   {   components.Dispose();  }  }  base.Dispose( disposing ); } #region Windows 窗體設計器生成的代碼 /// <summary> /// 設計器支持所需的方法 - 不要使用代碼編輯器修改 /// 此方法的內容。 /// </summary> private void InitializeComponent() {  this.groupBox1 = new System.Windows.Forms.GroupBox();  this.textBox1 = new System.Windows.Forms.TextBox();  this.groupBox2 = new System.Windows.Forms.GroupBox();  this.setTime = new System.Windows.Forms.DateTimePicker();  this.setDate = new System.Windows.Forms.DateTimePicker();  this.button1 = new System.Windows.Forms.Button();  this.button2 = new System.Windows.Forms.Button();  this.timer1 = new System.Timers.Timer();  this.groupBox1.SuspendLayout();  this.groupBox2.SuspendLayout();  ((System.ComponentModel.ISupportInitialize)(this.timer1)).BeginInit();  this.SuspendLayout();  //   // groupBox1  //   this.groupBox1.Controls.Add(this.textBox1);  this.groupBox1.Location = new System.Drawing.Point(32, 24);  this.groupBox1.Name = "groupBox1";  this.groupBox1.Size = new System.Drawing.Size(216, 64);  this.groupBox1.TabIndex = 0;  this.groupBox1.TabStop = false;  this.groupBox1.Text = "系統當前時間";  //   // textBox1  //   this.textBox1.Location = new System.Drawing.Point(16, 24);  this.textBox1.Name = "textBox1";  this.textBox1.ReadOnly = true;  this.textBox1.Size = new System.Drawing.Size(184, 21);  this.textBox1.TabIndex = 1;  this.textBox1.Text = "";  //   // groupBox2  //   this.groupBox2.Controls.Add(this.setTime);  this.groupBox2.Controls.Add(this.setDate);  this.groupBox2.Location = new System.Drawing.Point(32, 112);  this.groupBox2.Name = "groupBox2";  this.groupBox2.Size = new System.Drawing.Size(216, 64);  this.groupBox2.TabIndex = 1;  this.groupBox2.TabStop = false;  this.groupBox2.Text = "時間設置為";  //   // setTime  //   this.setTime.Format = System.Windows.Forms.DateTimePickerFormat.Time;  this.setTime.Location = new System.Drawing.Point(128, 24);  this.setTime.Name = "setTime";  this.setTime.ShowUpDown = true;  this.setTime.Size = new System.Drawing.Size(72, 21);  this.setTime.TabIndex = 1;  this.setTime.TabStop = false;  //   // setDate  //   this.setDate.Format = System.Windows.Forms.DateTimePickerFormat.Short;  this.setDate.Location = new System.Drawing.Point(8, 24);  this.setDate.Name = "setDate";  this.setDate.Size = new System.Drawing.Size(104, 21);  this.setDate.TabIndex = 0;  //   // button1  //   this.button1.Location = new System.Drawing.Point(40, 200);  this.button1.Name = "button1";  this.button1.Size = new System.Drawing.Size(64, 32);  this.button1.TabIndex = 2;  this.button1.Text = "設置";  this.button1.Click += new System.EventHandler(this.button1_Click);  //   // button2  //   this.button2.Location = new System.Drawing.Point(168, 200);  this.button2.Name = "button2";  this.button2.Size = new System.Drawing.Size(64, 32);  this.button2.TabIndex = 3;  this.button2.Text = "退出";  this.button2.Click += new System.EventHandler(this.button2_Click);  //   // timer1  //   this.timer1.Enabled = true;  this.timer1.SynchronizingObject = this;  this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Elapsed);  //   // Form1  //   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);  this.ClientSize = new System.Drawing.Size(280, 261);  this.Controls.Add(this.button2);  this.Controls.Add(this.button1);  this.Controls.Add(this.groupBox2);  this.Controls.Add(this.groupBox1);  this.Name = "Form1";  this.Text = "獲取和設置系統時間";  this.groupBox1.ResumeLayout(false);  this.groupBox2.ResumeLayout(false);  ((System.ComponentModel.ISupportInitialize)(this.timer1)).EndInit();  this.ResumeLayout(false); } #endregion /// <summary> /// 應用程序的主入口點。 /// </summary> [STAThread] static void Main()  {  Application.Run(new Form1()); } private void button2_Click(object sender, System.EventArgs e) {  this.Close(); // 關閉當前窗體 } private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {  // 清除textBox1上的字符串  textBox1.Clear();  // 創建SystemTime結構體,用于接收系統當前時間  SystemTime systemTime = new SystemTime();  GetLocalTime(ref systemTime); // 獲得系統的時間并存在SystemTime結構體中  // 將系統的時間從 SystemTime 結構體中中取出,并顯示在textBox1上  textBox1.Text += systemTime.wYear.ToString() +"-";  textBox1.Text += systemTime.wMonth.ToString() + "-";  textBox1.Text += systemTime.wDay.ToString() + " ";  textBox1.Text += systemTime.wHour.ToString() + ":";  textBox1.Text += systemTime.wMinute.ToString() + ":";  textBox1.Text += systemTime.wSecond.ToString(); // textBox1.Refresh();  } private void button1_Click(object sender, System.EventArgs e) {  // 創建SystemTime結構體,用于接收用戶設置的時間  SystemTime systemTime = new SystemTime();  // 從setDate,setTime控件中獲取年,月,日,小時,分鐘,秒信息,存入SystemTime結構體中      systemTime.wYear = (ushort)setDate.Value.Year;  systemTime.wMonth = (ushort)setDate.Value.Month;  systemTime.wDay = (ushort)setDate.Value.Day;  systemTime.wHour = (ushort)setTime.Value.Hour;  systemTime.wMinute = (ushort)setTime.Value.Minute;  systemTime.wSecond = (ushort)setTime.Value.Second;  // 將系統的時間設置為用戶指定的時間  SetLocalTime(ref systemTime); } }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
上原亚衣av一区二区三区| 国产精品99久久99久久久二8| 欧美在线国产精品| 欧美国产欧美亚洲国产日韩mv天天看完整| 国产精品激情自拍| 欧美丰满少妇xxxx| 亚洲在线免费看| 91亚洲精品久久久| 国产精品高潮呻吟久久av无限| 欧美美最猛性xxxxxx| 日本欧美一级片| 91精品国产91久久久| 久久免费精品视频| 日本免费久久高清视频| 亚洲精品久久久久久下一站| 欧美日韩精品在线视频| 日韩美女免费观看| 欧美高清视频在线| 亚洲欧美制服丝袜| 日韩欧美国产中文字幕| 国产精品久久久精品| 欧美激情三级免费| 黄网站色欧美视频| 欧美日韩中文字幕日韩欧美| 国产精品久久久久久久久久小说| 麻豆乱码国产一区二区三区| 国产精品视频自拍| 欧美日韩第一视频| 欧美一级大片在线观看| 日韩av电影中文字幕| 欧美成人久久久| 亚州国产精品久久久| 亚洲精品网站在线播放gif| 日韩在线观看免费全集电视剧网站| 欧美大尺度激情区在线播放| 欧美激情国产日韩精品一区18| 亚洲国产91精品在线观看| 日本在线观看天堂男亚洲| 亚洲欧美激情视频| 国产精品久久久久久搜索| 欧美精品日韩三级| 国产精品一久久香蕉国产线看观看| 亚洲四色影视在线观看| 亚洲人高潮女人毛茸茸| 黄色精品在线看| 国内外成人免费激情在线视频| 精品国产一区二区三区久久狼5月| 久久久视频在线| 欧美极品少妇xxxxⅹ喷水| 日本久久中文字幕| 成人av.网址在线网站| 国产亚洲精品久久久| 亚洲天堂男人天堂女人天堂| 日韩在线精品一区| 亚洲香蕉成人av网站在线观看| 欧美巨猛xxxx猛交黑人97人| 亚洲嫩模很污视频| 91久久国产精品91久久性色| 在线看国产精品| 亚洲老头同性xxxxx| 久久精品中文字幕电影| 日韩精品在线视频观看| 久久理论片午夜琪琪电影网| 日本高清不卡的在线| 日韩精品在线私人| 欧美日本高清一区| 日本中文字幕成人| 亚洲第一免费网站| 日韩在线观看免费全| 欧洲精品毛片网站| 午夜精品一区二区三区在线视| 成人午夜在线影院| 日韩中文字幕免费视频| 在线日韩中文字幕| 久久久久国产一区二区三区| 国产高清在线不卡| 亚洲电影免费观看| 国产精品av免费在线观看| 亚洲日本成人网| 欧美猛少妇色xxxxx| 九九精品视频在线观看| 中文字幕日韩综合av| 欧美日韩国产一区中文午夜| 中文字幕亚洲一区二区三区五十路| 日韩精品在线观看网站| 久久久免费高清电视剧观看| 91日本视频在线| 色婷婷亚洲mv天堂mv在影片| 欧美xxxx做受欧美| 2021国产精品视频| 亚洲女人初尝黑人巨大| 日韩美女在线播放| 91亚洲精品久久久| 91老司机精品视频| 久久理论片午夜琪琪电影网| 日韩在线视频线视频免费网站| 国产亚洲aⅴaaaaaa毛片| 国产91精品黑色丝袜高跟鞋| 日韩电影中文字幕| 久久久久久久香蕉网| 国产免费一区二区三区在线观看| 91在线国产电影| 亚洲欧美精品一区| 国产日产亚洲精品| 欧美电影免费在线观看| 九九热精品视频在线播放| 日韩av中文字幕在线播放| 亚洲国产精品专区久久| 日韩在线免费观看视频| 国产精品久久久久久久久久免费| 亚洲欧美制服另类日韩| 7777kkkk成人观看| 亚洲激情在线观看| 亚洲娇小xxxx欧美娇小| 精品欧美国产一区二区三区| 日韩精品有码在线观看| 亚洲v日韩v综合v精品v| 久久成人综合视频| 亚洲 日韩 国产第一| xxav国产精品美女主播| 91在线免费网站| 欧美激情久久久| 国产日韩在线精品av| 性日韩欧美在线视频| 国产成人综合精品| 精品国产欧美成人夜夜嗨| 国产98色在线| 久久久亚洲影院| 国内揄拍国内精品| 亚洲成人亚洲激情| 精品女厕一区二区三区| 57pao成人国产永久免费| 亚洲性猛交xxxxwww| 美女福利精品视频| 亚洲欧美一区二区三区四区| 欲色天天网综合久久| 性色av一区二区三区在线观看| 97av在线视频免费播放| 国产精品无码专区在线观看| 久久亚洲综合国产精品99麻豆精品福利| 亚洲国产精品va在线观看黑人| 午夜欧美大片免费观看| 欧美大秀在线观看| 成人黄色激情网| 精品国产91久久久久久| 欧美一区视频在线| 最近日韩中文字幕中文| 国产精品亚洲片夜色在线| 国内精品小视频在线观看| 久久6免费高清热精品| 日韩视频免费看| 欧美伦理91i| 91久久久久久| www.99久久热国产日韩欧美.com| 欧美在线性爱视频| 亚洲成人激情在线观看| 久久久久久亚洲精品| 蜜臀久久99精品久久久久久宅男| 美女视频久久黄| 亚洲成人av片在线观看| 国产婷婷色综合av蜜臀av| 欧美激情一区二区三级高清视频| 中文字幕欧美日韩va免费视频| 精品亚洲永久免费精品|