• Python 时间 今日,昨天, 周, 月


    # 今日
    import time
    today_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

      

    # 昨天
    import datetime
    cur_date = datetime.datetime.now().date() yester_day = cur_date - datetime.timedelta(days=1)

      

    # 周
    import datetime
    def get_current_week(): monday, sunday = datetime.date.today(), datetime.date.today() one_day = datetime.timedelta(days=1) while monday.weekday() != 0: monday -= one_day while sunday.weekday() != 6: sunday += one_day return str(monday), str(sunday)

      

    # 月
    from datetime import datetime
    currentYear = datetime.now().year # 年 currentMonth = datetime.now().month # 月 currentDay = datetime.now().day # 天 year_month = str(currentYear) + "-" + str(currentMonth) + "-" + "01 00:00:00" year_month_day = str(currentYear) + "-" + str(currentMonth) + "-" + str(currentDay) + " 23:59:59"

      

  • 相关阅读:
    Go视频教程
    Mysql常用
    同步Redux
    React跨组件通讯
    React组件通讯
    React
    git生成公钥和私钥
    常用经典算法---希尔排序
    string和c_str()使用时的坑
    腾讯云python网站开发环境搭建
  • 原文地址:https://www.cnblogs.com/wuyongcong/p/14949005.html
Copyright © 2020-2023  润新知