Python 获取列表中当前月份的日期以及日期的差异

Python 获取列表中当前月份的日期以及日期的差异,python,datetime,calendar,Python,Datetime,Calendar,如何打印这些文件: 在任何时候,我都应该能够在列表中返回本月的日期。 由于现在是三月,我想打印一个列表 查找当前日期与当月第一天的天数差异 e、 今天是三月四日。我应该可以将差异打印为3 提前谢谢 下面是在Python2.7.3中可以执行的操作 from datetime import date import calendar today = date.today() first_of_month = today.replace(day=1) _, number_of_days_in_m

如何打印这些文件:

  • 在任何时候,我都应该能够在列表中返回本月的日期。 由于现在是三月,我想打印一个列表

  • 查找当前日期与当月第一天的天数差异

    e、 今天是三月四日。我应该可以将差异打印为3 提前谢谢


  • 下面是在Python2.7.3中可以执行的操作

    from datetime import date 
    import calendar
    today = date.today()
    
    first_of_month = today.replace(day=1)
    _, number_of_days_in_month = calendar.monthrange(first_of_month.year, first_of_month.month)
    
    for i in range(1, number_of_days_in_month+1):
        newdate = today.replace(day = i)
        print newdate #prints all dates in months
    
    #Lets calculate difference between 14th of this month and 1st
    randomdate = today.replace(day=14)
    delta = randomdate - first_of_month
    print delta.days
    

    你有问题吗?在我看来,这个问题被标记为“python”,它显然是在问如何打印当前月份的日期。不知道为什么要以“问题不清楚”为由关闭这家公司?