在服务器端:
[WebMethod]
public DateTime GetServerDateTime()
{
return DateTime.Now;
}
在客户端:
[StructLayout(LayoutKind.Sequential)]
public struct SystemTime
{
public short wYear;
public short wMonth;
public short wDayOfWeek;
public short wDay;
public short wHour;
public short wMinute;
public short wSecond;
public short wMilliseconds;
public SystemTime(DateTime dt)
{
wYear = (short)dt.Year;
wMonth = (short)dt.Month;
wDayOfWeek = (short)dt.DayOfWeek;
wDay = (short)dt.Day;
wHour = (short)dt.Hour;
wMinute = (short)dt.Minute;
wSecond = (short)dt.Second;
wMilliseconds = (short)dt.Millisecond;
}
}
[DllImport("kernel32.dll")]
public static extern bool SetLocalTime(ref SystemTime systime);
private void btnLogin_Click(object sender, EventArgs e)
{
SystemTime dt = new SystemTime(Service.GetServerDateTime());
SetLocalTime(ref dt);
}