zoukankan      html  css  js  c++  java
  • python中常见的日期处理方法

    今天:today = datetime.date.today()

    昨天:yesterday = today - datetime.timedelta(days=1)

    上个月:last_month = today.month - 1 if today.month - 1 else 12

    当前时间戳:time_stamp = time.time()

    各种类型的转换

    时间戳转datetime:datetime.datetime.fromtimestamp(time_stamp)

    datetime转时间戳:int(time.mktime(today.timetuple()))

    datetime转字符串:today_str = today.strftime("%Y-%m-%d")

    字符串转datetime:today = datetime.datetime.strptime(today_str,"%Y-%m-%d")

    补时差:today + datetime.timedelta(hours=8)

  • 相关阅读:
    开通博客了
    nginx一些高级配置
    hue的优化
    hue改下载行数
    运维常用脚本
    scala
    kafka调优
    confluent部署:
    Redis主从及哨兵
    Redis配置
  • 原文地址:https://www.cnblogs.com/gaojr/p/12082370.html
Copyright © 2011-2022 走看看