Python list of first day of month for given period

后端 未结 8 1597
有刺的猬
有刺的猬 2021-02-09 02:20

I am trying find an efficient way of creating a list of dates only including the first day of the month for a given period. Something like this but better:

impor         


        
8条回答
  •  别那么骄傲
    2021-02-09 02:52

    import datetime 
    import calendar 
    import re
    from datetime import date
    
    def findDay(date): 
        born = datetime.datetime.strptime(date, '%Y %m %d').weekday() 
        return (calendar.day_name[born]) 
    
    def hyp(j):    
        no_hyphens = re.sub('-',' ',str(j))
        return no_hyphens
    
    def send(year_start):    
        date = hyp(year_start)
        print (date)
        print(findDay(date))
    
    epoch_year = 2019
    for i in range(1,13):
        year_start = date(epoch_year, i, 1)
        send(year_start)
    

提交回复
热议问题