public class LibWrapDateTime
{
[DllImportAttribute( "Kernel32.dll" )]
public static extern void SetLocalTime(SystemTime st );
}
[StructLayoutAttribute( LayoutKind.Sequential)]
public class SystemTime
{
public ushort wYear;
public ushort wMonth;
public ushort wDayOfWeek;
public ushort wDay;
public ushort wHour;
public ushort wMinute;
public ushort wSecond;
public ushort wMilliseconds;
}
引用:
object oServerTime = SqlHelper.ExecuteScalar(ConnectionString, CommandType.Text,
"SELECT GETDATE()");
if (oServerTime != null && oServerTime!= DBNull.Value)
{
System.DateTime serverTime = Convert.ToDateTime(oServerTime);
SystemTime MySystemTime = new SystemTime();
MySystemTime.wYear=(ushort)serverTime.Year;
MySystemTime.wMonth=(ushort)serverTime.Month;
MySystemTime.wDay=(ushort)serverTime.Day;
MySystemTime.wHour=(ushort)serverTime.Hour;
MySystemTime.wMinute=(ushort)serverTime.Minute;
MySystemTime.wSecond=(ushort)serverTime.Second;
LibWrapDateTime.SetLocalTime(MySystemTime);
}