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
-
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)
-
KInd of a duplicate of http://stackoverflow.com/questions/516977/updating-system-time-in-visual-studio-using-netc?
-
And How do I exactly set these values to the ones that I get from the service???
-
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.
0 comments:
Post a Comment