【问题标题】:exception when using time.strftime [duplicate]使用 time.strftime 时出现异常 [重复]
【发布时间】:2016-02-03 08:39:52
【问题描述】:

我有一个严重的“在我的机器上工作”的案例:)

考虑以下简单代码:

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

【问题讨论】:

标签: python ironpython


【解决方案1】:

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

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

strftime 只是提供了这个时间对象的格式。

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

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

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

你可能最适合:

import datetime as dt

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-07
    • 1970-01-01
    • 2017-06-04
    • 2018-08-05
    • 1970-01-01
    • 2017-05-13
    • 1970-01-01
    • 2016-06-28
    相关资源
    最近更新 更多