I have a web service running that is returning a time. I want to update my system's time with the time that my service is returning . How can I do this in visual studio using C#?
Edit: Exact duplicate of: Set time programmatically using C#
I have a web service running that is returning a time. I want to update my system's time with the time that my service is returning . How can I do this in visual studio using C#?
Edit: Exact duplicate of: Set time programmatically using C#
Why are you bothering to re-invent the wheel?
Windows already has a built in NTP/time service, that will sync the time with any of the public time servers or a private one that you create.
I would write a wrapper for the windows API SetSystemTime. Something like this:
[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;
}
[DllImport("kernel32.dll", SetLastError=true)]
public static extern bool SetSystemTime( [In] ref SYSTEMTIME st );
(Please note that I have not tested this, but it should get you started)