【问题标题】:Error : strptime() argument 1 must be str, not int错误:strptime() 参数 1 必须是 str,而不是 int
【发布时间】:2022-11-21 14:30:04
【问题描述】:

我试图减去两次并得到一个错误。在下面总错误即将到来

if result[0]['outTime'] != None:
type = "bothPunchDone"
FMT = '%H:%M:%S'
total= datetime.strptime(result[0]['outTime'], FMT) - datetime.strptime(result[0]['inTime'], FMT)

我试过但无法解决问题。

【问题讨论】:

  • result[0]['outTime'] 是这个字符串还是 int 检查然后如果它是 int 你可以使用 str(result[0]['outTime']) 将它转换为 sting
  • 我当前的时间格式 = datetime.now().strftime("%H:%M:%S")
  • 尝试打印 type(result[0]['out Time'] ) 和 type(result[0]['in Time']) 并查看

标签: python django time


【解决方案1】:
from datetime import datetime

result = datetime.now().strftime("%H:%M:%S")

if result != None:
    type = "bothPunchDone"
    
FMT = '%H:%M:%S'
total= datetime.strptime(result, FMT) - datetime.strptime(result, FMT)

print(total)

正在为我工​​作。尝试检查result[0]['outTime']的类型

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-11
    • 1970-01-01
    • 1970-01-01
    • 2018-09-04
    • 1970-01-01
    • 1970-01-01
    • 2018-10-11
    相关资源
    最近更新 更多