Infer year from day of week and date with python datetime
问题 I have data which is of the form Thu Jun 22 09:43:06 and I would like to infer the year from this to use datetime to calculate the time between two dates. Is there a way to use datetime to infer the year given the above data? 回答1: No, but if you know the range (for example 2010..2017), you can just iterate over years to see if Jun 22 falls on Thursday: def find_year(start_year, end_year, month, day, week_day): for y in range(start_year, end_year+1): if datetime.datetime(y, month, day, 0, 0)