在 vb.net 中获取 Internet 时间而不是 pc 时间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22297089/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 17:01:08  来源:igfitidea点击:

Get Internet Time instead of pc time in vb.net

vb.netwinformsreal-time

提问by Unknownymous

I have an application that runs on local machines (multiple users) most likely its like a DTR system. This application is based on client-server architecture, so in this I need the same time over all the PCs, so by any method when on any PC application starts it fetch the current time from internet or from any server which provide accurate and same time to all the users. I searched other solutions but its no luck.

我有一个在本地机器(多用户)上运行的应用程序,很可能就像一个 DTR 系统。此应用程序基于客户端 - 服务器架构,因此在此我需要在所有 PC 上使用相同的时间,因此通过任何方法在任何 PC 应用程序上启动时,它都会从 Internet 或任何提供准确和相同时间的服务器获取当前时间给所有用户。我搜索了其他解决方案,但没有运气。

Any ideas and alternatives is much appreciated!

任何想法和替代方案都非常感谢!

回答by Jens

You can query an NTP server. This is basically a server that offers information about the current time. There are servers like pool.ntp.org or google time servers under time1.google.com and so on.

您可以查询NTP服务器。这基本上是一个提供当前时间信息的服务器。有pool.ntp.org之类的服务器或者time1.google.com下的google时间服务器等等。

In order to query these you can refer to previous answers with complete code like this on:

为了查询这些,您可以参考以前的答案,完整代码如下:

How to Query an NTP Server using C#?

如何使用 C# 查询 NTP 服务器?

It's in C# but you can easily convert it to VB.net with tools like http://codeconverter.sharpdevelop.net/SnippetConverter.aspx

它在 C# 中,但您可以使用http://codeconverter.sharpdevelop.net/SnippetConverter.aspx 等工具轻松将其转换为 VB.net