【问题标题】:Use current time of the day as an integer in python在python中使用当前时间作为整数
【发布时间】:2017-06-21 17:24:11
【问题描述】:

我希望创建一个涉及当前时间的 if then 语句。例如,我想要一些东西,如果它已经过了下午 2 点,然后执行此功能。

我尝试过使用时间模块,但我似乎无法找到一种方法来获取一天中的时间,而无需像日期这样的额外内容。有什么帮助吗?

【问题讨论】:

  • 您应该始终从发布您尝试过但不起作用的内容开始,然后从那里开始。

标签: python time clock


【解决方案1】:

这是一个开始,我认为这足以让您获得答案并根据需要使用它。

import time
print(time.strftime("%Y-%m-%d %H:%M"))
print(time.strftime("I can format the date and time in many ways. Time is: %H:%M"))

输出(当我运行它时):

2017-06-21 10:40
I can format the date and time in many ways. Time is: 10:40

【讨论】:

    猜你喜欢
    • 2011-01-04
    • 2012-10-20
    • 2011-07-08
    • 2020-04-05
    • 1970-01-01
    • 1970-01-01
    • 2018-09-19
    • 1970-01-01
    • 2011-07-02
    相关资源
    最近更新 更多