zoukankan      html  css  js  c++  java
  • Python 获得最近一个月的每天的日期

    直接上代码:

    #coding:utf-8
    # from common.contest import *
    
    
    import datetime
    import time
    begin_date = (datetime.datetime.now() - datetime.timedelta(days =30)).strftime("%Y-%m-%d")
    date_list = []
    begin_date = datetime.datetime.strptime(begin_date, "%Y-%m-%d")
    end_date = datetime.datetime.strptime(time.strftime('%Y-%m-%d',time.localtime(time.time())), "%Y-%m-%d")
    while begin_date <= end_date:
        date_str = begin_date.strftime("%Y-%m-%d")
        date_list.append(date_str)
        begin_date += datetime.timedelta(days=1)
    
    
    print date_list

    输出结果是:

    C:Python27python.exe E:/squid_frame/weibo_pc_spider_local/test.py
    ['2019-03-18', '2019-03-19', '2019-03-20', '2019-03-21', '2019-03-22', '2019-03-23', '2019-03-24', '2019-03-25', '2019-03-26', '2019-03-27',
    '2019-03-28', '2019-03-29', '2019-03-30', '2019-03-31', '2019-04-01', '2019-04-02', '2019-04-03', '2019-04-04', '2019-04-05', '2019-04-06',
    '2019-04-07', '2019-04-08', '2019-04-09', '2019-04-10', '2019-04-11', '2019-04-12', '2019-04-13', '2019-04-14', '2019-04-15', '2019-04-16',
    '2019-04-17'] Process finished with exit code 0
  • 相关阅读:
    Probability theory
    python Memo
    numpy 札记
    linux LVM 逻辑卷
    关于TF-IDF的一些见解
    Python之list、dict、np等常用数值运算
    Python之matplotlib绘图
    Python之打开网页
    Python之获取地址经纬度
    两台电脑直接共享文件
  • 原文地址:https://www.cnblogs.com/xuchunlin/p/10722623.html
Copyright © 2011-2022 走看看