One:
Two: Code
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Runtime.InteropServices;namespacesetdate{ Public Partial classFrm_main:form { PublicFrm_main () {InitializeComponent (); } Public classSetsystemdatetime//custom class Setsystemdatetime, used to set the system date, in order to use the DllImportAttribute class (The DllImportAttribute class refers to the ability to apply an attribute to a method,//and is exposed as a static entry point by an unmanaged dynamic-link library (DLL).//namespaces need to be introduced: using System.Runtime.InteropServices;{[DllImportAttribute ("Kernel32.dll")]//Initializes a new instance of the DllImportAttribute class with the name of the DLL that contains the method to be imported. Public Static extern voidGetlocaltime (SystemTime St);//C # To set the system time must call the Win32 API, where the related function is SetSystemTime (), Getsystemtimer (), Setlocaltime (), Getlocaltime (),//this seems to be a VC write function, in VC + + can be directly called. //for these two functions, the input parameter must be a struct of the following, whose member variable type must be ushort, and the member variable cannot be changed in order. [DllImportAttribute ("Kernel32.dll")] Public Static extern voidSetlocaltime (SystemTime St); } [StructLayoutAttribute (layoutkind.sequential)] Public classSystemTime//Custom class SystemTime for defining date classes { Public ushortVyear;//years Public ushortVmonth;//Month Public ushortVdayofweek;//Week Public ushortVDay;//Day Public ushortVhour;//hours Public ushortVminute;//points Public ushortVsecond;//seconds } Private voidButton1_Click (Objectsender, EventArgs e) { This. TextBox1.Text = DateTime.Now.ToString ("F") +//get the system time " "+ DateTime.Now.ToString ("dddd"); } Private voidButton2_Click (Objectsender, EventArgs e) { if(MessageBox.Show ("Are you sure you want to change the system's current date? ",//set the system current date time "Information Tips", messageboxbuttons.ok) = =DialogResult.OK) {DateTime year= This. Datetimepicker1.value;//Get time InformationSystemTime MySystemTime=NewSystemTime ();//creating objects for the system time classSetsystemdatetime.getlocaltime (mysystemtime);//get the system timeMysystemtime.vyear= (ushort) This. dateTimePicker1.Value.Year;//Set YearMysystemtime.vmonth = (ushort) This. DateTimePicker1.Value.Month;//Set MonthMysystemtime.vday = (ushort) This. DateTimePicker1.Value.Day;//Set DayMysystemtime.vhour = (ushort) This. DateTimePicker2.Value.Hour;//Set HoursMysystemtime.vminute = (ushort) This. DateTimePicker2.Value.Minute;//Set pointsMysystemtime.vsecond = (ushort) This. DateTimePicker2.Value.Second;//Set secondsSetsystemdatetime.setlocaltime (mysystemtime);//Setting the system timeButton1_Click (NULL,NULL);//Perform a button click event } } }}