使用time.strftime时的异常

时间:2016-02-03 08:39:53

标签: python ironpython

我有一个严重的情况"在我的机器上运行" :)

考虑以下简单代码:

import time

t = time.strftime("%Y%m%d")

此代码部署到具有共享的服务器,并从那里启动30个Windows客户端。 从我的机器运行它时它可以工作,但任何其他客户端都会收到错误

  

IronPython.Runtime.Exceptions.ImportException:没有名为time的模块

我通过恢复到.NET DateTime来修复它

from System import DateTime
d = DateTime.Now

但是我仍然想知道为什么python版本不起作用。我使用的是IronPython 2.7.5

1 个答案:

答案 0 :(得分:0)

time只是一个时间对象,没有日期。

>>> time?
Docstring:
time([hour[, minute[, second[, microsecond[, tzinfo]]]]]) --> a time object

strftime只提供此时间对象的格式。

time.strftime?
Docstring: format -> strftime() style string.

根据docstime模块提供各种与时间相关的功能。有关相关功能,另请参阅日期时间和日历模块。

  

虽然此模块始终可用,但并非所有平台上都提供所有功能。

你可能最喜欢:

import datetime as dt

t = dt.datetime.now().strftime("%Y%m%d")