要修改系统时间,但是修改了始终不对,好像背截取了,只修改了部分时间,大家看看这个是什么情况
#region 设置系统时间 [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 wMiliseconds;
}
[DllImport("coredll")]
public static extern bool SetSystemTime(ref SystemTime sysTime); //设置系统时间 [DllImport("coredll")]
public static extern bool GetSystemTime(ref SystemTime sysTime); //设置系统时间
public static bool setSystemTime(DateTime dt)
{
try
{
SystemTime time = new SystemTime();
GetSystemTime(ref time);
time.wYear = (short)dt.Year;
time.wMonth = (short)dt.Month;
time.wDay = (short)dt.Day;
time.wHour = (short)dt.Hour;
time.wMinute = (short)dt.Minute;
time.wSecond = (short)dt.Second;
SetSystemTime(ref time);
return true;
}
catch
{
return false;
} } #endregion
设置是成功的,在小时上是对不上的,分析看是不是代码问题,short/USHORT都是一样的情况
#region 设置系统时间 [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 wMiliseconds;
}
[DllImport("coredll")]
public static extern bool SetSystemTime(ref SystemTime sysTime); //设置系统时间 [DllImport("coredll")]
public static extern bool GetSystemTime(ref SystemTime sysTime); //设置系统时间
public static bool setSystemTime(DateTime dt)
{
try
{
SystemTime time = new SystemTime();
GetSystemTime(ref time);
time.wYear = (short)dt.Year;
time.wMonth = (short)dt.Month;
time.wDay = (short)dt.Day;
time.wHour = (short)dt.Hour;
time.wMinute = (short)dt.Minute;
time.wSecond = (short)dt.Second;
SetSystemTime(ref time);
return true;
}
catch
{
return false;
} } #endregion
设置是成功的,在小时上是对不上的,分析看是不是代码问题,short/USHORT都是一样的情况
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货