In C#, how do I query a remote server for its current time?
Similar functionality to
net time \\servername
but returning a datestamp that includes seconds.
Thanks
In C#, how do I query a remote server for its current time?
Similar functionality to
net time \\servername
but returning a datestamp that includes seconds.
Thanks
You can use the NetRemoteTOD function.
An example from http://bytes.com/groups/net-c/246234-netremotetod-usage:
Simple Network Time Protocol Client
You can try getting the daytime on port 13:
If you have access to the filesystem of the remote system with a UNC path (like
\\remotehost\foo\bar
; for instance using Windows Explorer), you can retrieve remote datetime, even if it's not a Windows system, with following workaround. Create a dummy file, read it's write time and throw it away. It works also for local host.Using the C# NTP client in Reed Copsey (& David Laing) answer, you can get a time "now" stamp (in ms) from a domain controller / NTP server using:
Below is a more complete implementation.
Usage:
DateTime? now = RemoteTOD.GetNow(@"\\ServerName");