Using system. drawing;
Using system. componentmodel;
Using system. runtime. interopservices;
[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;
}
Public class Win32
{
[Dllimport ("kernel32.dll")]
Public static extern bool setsystemtime (ref systemtime retry IME );
[Dllimport ("kernel32.dll")]
Public static extern void getsystemtime (ref systemtime policime );
}
# Region Time Synchronization
/// <Summary>
/// Set the synchronization time with the server
/// </Summary>
Public void synchronoustime ()
{
Try
{
# Region change computer time
Systemtime required IME = new systemtime ();
Datetime servertime = convert. todatetime ("2005-01-18 ");
Required ime. wyear = convert. touint16 (servertime. year );
Required ime. wmonth = convert. touint16 (servertime. month );
Required ime. wday = convert. touint16 (servertime. Day );
// Disposal at Beijing Time
Int nbeijinghour = servertime. Hour-8;
If (nbeijinghour <= 0)
{
Nbeijinghour + = 24;
Required ime. wday = convert. touint16 (servertime. Day-1 );
Systime. wdayofweek = convert. touint16 (servertime. dayofweek-1 );
}
Else
{
Required ime. wday = convert. touint16 (servertime. Day );
Systime. wdayofweek = convert. touint16 (servertime. dayofweek );
}
Systime. whour = convert. touint16 (nbeijinghour );
Systime. wminute = convert. touint16 (servertime. Minute );
Systime. wsecond = convert. touint16 (servertime. Second );
Systime. wmiliseconds = convert. touint16 (servertime. millisecond );
Win32.setsystemtime (ref systime );
# endregion
}< br> catch
{< br> // if an error occurs, no exception is thrown.
}< BR ># endregion