在C#中,如何查询远程服务器的当前时间?
类似的功能
net time \\servername
Run Code Online (Sandbox Code Playgroud)
但返回包含秒的日期戳.
谢谢
您可以使用NetRemoteTOD功能.
来自http://bytes.com/groups/net-c/246234-netremotetod-usage的示例:
// The pointer.
IntPtr pintBuffer = IntPtr.Zero;
// Get the time of day.
int pintError = NetRemoteTOD(@"\\sony_laptop", ref pintBuffer);
// Get the structure.
TIME_OF_DAY_INFO pobjInfo = (TIME_OF_DAY_INFO)
Marshal.PtrToStructure(pintBuffer, typeof(TIME_OF_DAY_INFO));
// Free the buffer.
NetApiBufferFree(pintBuffer);
Run Code Online (Sandbox Code Playgroud)
Windows 时间服务实现 NTP。这是NTP 客户端的 C# 实现。使用它的 Windows GUI 可以在Simple Network Time Protocol Client中找到。这是瓦勒·博坎的作品。
归档时间: |
|
查看次数: |
21005 次 |
最近记录: |