我已使用以下程序更改系統日期時間。在C#中更改系統日期時間.Date已更改,但TIme未在64位Windows Server 2008中更改
public struct SystemTime
{
public ushort Year;
public ushort Month;
public ushort DayOfWeek;
public ushort Day;
public ushort Hour;
public ushort Minute;
public ushort Second;
public ushort Millisecond;
};
[DllImport("kernel32.dll", EntryPoint = "GetSystemTime", SetLastError = true)]
public extern static void Win32GetSystemTime(ref SystemTime sysTime);
[DllImport("kernel32.dll", EntryPoint = "SetSystemTime", SetLastError = true)]
public extern static bool Win32SetSystemTime(ref SystemTime sysTime);
private void button1_Click(object sender, EventArgs e)
{`enter code here`
// Set system date and time
SystemTime updatedTime = new SystemTime();
updatedTime.Year = (ushort)2009;
updatedTime.Month = (ushort)3;
updatedTime.Day = (ushort)16;
updatedTime.Hour = (ushort)10;
updatedTime.Minute = (ushort)0;
updatedTime.Second = (ushort)0;
// Call the unmanaged function that sets the new date and time instantly
Win32SetSystemTime(ref updatedTime);
}
系統日期改變但時間不變。 我的任務是讓NTP服務器時間和更改系統的日期和時間,NTP服務器time.Im的獲取NTP服務器的日期和時間&改變日期,但林不能夠改變我的系統的時間
「討論板」並不適合與C#相關的編程問題。請使用實際適用於您提問的問題的標籤,以便它們能夠正確分類以進行搜索,並獲得可能幫助您獲得答案的人員的關注。不要無緣無故地抓取隨機標籤。謝謝。 –
可能的重複[我無法讓SetSystemTime在Windows Vista中使用C#與Interop(P/Invoke)]工作(http://stackoverflow.com/questions/2486125/i-cant-get-setsystemtime-to-work -in-windows-vista-using-c-sharp-with-interop-p) –
是不是正在同步到內置於Windows的NTP服務器? –