TTyb

Python时间和时间戳互相转换

# 将时间变成时间戳
def tranftimestamp(stringtime):
    try:
        return time.mktime(time.strptime(stringtime, "%Y-%m-%d %H:%M:%S.%f"))
    except:
        return time.mktime(time.strptime(stringtime, "%Y-%m-%d %H:%M:%S"))


# 将时间戳转化为时间
def tranftime(timestamp):
    return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timestamp))

分类:

技术点:

相关文章:

  • 2021-12-05
  • 2021-12-05
  • 2021-12-15
  • 2022-02-24
  • 2021-12-10
  • 2022-02-21
  • 2021-11-28
  • 2021-12-10
猜你喜欢
  • 2022-12-23
  • 2021-11-02
  • 2021-12-08
  • 2021-12-05
相关资源
相似解决方案