小编Rob*_*man的帖子

如何从NTP服务器获取时间?

我需要从 NTP 服务器获取英国的时间。在网上找到了一些东西,但是每当我尝试代码时,我总是得到一个返回日期时间,与我的计算机相同。我更改了计算机上的时间以确认这一点,并且我总是得到这一点,因此它不是来自 NTP 服务器。

import ntplib
from time import ctime
c = ntplib.NTPClient()
response = c.request('uk.pool.ntp.org', version=3)
response.offset
print (ctime(response.tx_time))
print (ntplib.ref_id_to_text(response.ref_id))

x = ntplib.NTPClient()
print ((x.request('ch.pool.ntp.org').tx_time))
Run Code Online (Sandbox Code Playgroud)

python ntp

8
推荐指数
2
解决办法
2万
查看次数

创建文件后删除文件

所以我正在创建 dll 类型文件,运行它们,然后我想删除它们。

然而,当我尝试删除它们时,我得到一个异常,因为它声称它们仍在被另一个进程使用。

我假设用于创建文件的代码没有正确处理资源以允许删除文件,这是我创建文件的代码。

if (!Directory.Exists(PathToRobots + Generation))
{
    Directory.CreateDirectory(PathToRobots + Generation);
}

File.WriteAllText(Path.Combine(PathToRobots + Generation, NameSpace + GetRobotName() + robotNumber + ".cs"), code);


CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerParameters parameters = new CompilerParameters()
{
    GenerateInMemory = false,
    GenerateExecutable = false, // True = EXE, False = DLL
    IncludeDebugInformation = true,
    OutputAssembly = Path.Combine(FileName + ".dll") // Compilation name
};

parameters.ReferencedAssemblies.Add(@"robocode.dll");

CompilerResults results = provider.CompileAssemblyFromSource(parameters, code);

if (results.Errors.HasErrors)
{
    StringBuilder sb = new StringBuilder();

    foreach (CompilerError error in results.Errors) …
Run Code Online (Sandbox Code Playgroud)

c# file

5
推荐指数
1
解决办法
215
查看次数

标签 统计

c# ×1

file ×1

ntp ×1

python ×1