Due to the problem of the main board, it is lost time, so I think a method is to get the latest time from the Internet, so I don't need to go to the time, the network is all, the time can automatically correct.
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Data.SqlClient; using System.Text; using System.IO; using System. Runtime.InteropServices;
Namespace AutoExitWindows {///
public ReSetLocalTimeFromNetwork (string Server, string Port, string TimeZone) {try {// get the Network Time SNTPTimeClient client = new SNTPTimeClient (Server, Port); client.Connect (); string strTest = client.ToString (); Console.Write ( strTest);
// Remove the year, month, day, hour, minute, second, microsecond, int ModMonth, INTDAYOFWEEK, INTDAY, INTHOUR, INTMINUTE, INTSECOND, INTMILLISECONDS; Char [] split = new char [1]; split [0] = Convert.TOCHAR ("/ n"); string [] temp = strTest.split (split, 100); string strdate = ""; int idos = -1; for (int i = 0; i // Setting up local time // When setting, it should be Greenwich Time DateTime DTMDATE = Convert.TodateTime (strdate); DTMDATE = DTMDATE.ADDHOURS ((- 1) * Convert.Toint16 (Timezone)) ; intYear = Convert.ToInt16 (dtmDate.Year); intMonth = Convert.ToInt16 (dtmDate.Month); intDayofWeek = Convert.ToInt16 (dtmDate.DayOfWeek); intDay = Convert.ToInt16 (dtmDate.Day); intHour = Convert.ToInt16 (DTMDATE. Hour); INTMINUTE = Convert.Toint16 (dtmdate.minute); intSecond = Convert.Toint16 (dtmdate.second); INTMILLISECONDS = Convert.Toint16 (DTMDate.MilliseCond); SYSTEMTIME systime = new SYSTEMTIME (intYear, intMonth, intDayofWeek, intDay, intHour, intMinute, intSecond, intMilliseconds); int intValue = SetSystemTime (ref systime); if (intValue == 0) {intValue = GetLastError (); throw new Exception ( INTVALUE.TOSTRING () "Error, can't set local time.");} //messagebox.show (intValue.tostring () "/ n" DateTime.now.toString () "/ n" STRDATE);} catch (exception E1) {throw E1;}}}} When calling: resetLocalTimeFromNetwork Objresettime = New ResetLocalTimeFromNetWork (Strremoteip, StrremotEport, Strtimezone);