tags:

views:

230

answers:

4

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: http://stackoverflow.com/questions/204936/set-time-programmatically-using-c

+1  A: 

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)

Khadaji
A: 

And How do I exactly set these values to the ones that I get from the service???

+2  A: 

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.

StingyJack