程序员!在我的钢琴演奏会之前,我有一个关于如何制作倒计时日历的问题;就像一个有趣的侧面项目。所以,记住这一点,我创建了这段代码:
#!/usr/bin/python
import os
import numpy
import time
import commands
days = 59
(status, txt) = commands.getstatusoutput('date')
txt = txt.replace('EDT','')
txt = txt.replace('2016','')
if 'Mon' in txt:
txt = txt.replace('Mon','')
elif 'Tue' in txt:
txt = txt.replace('Tue','')
elif 'Wed' in txt:
txt = txt.replace('Wed','')
elif 'Thu' in txt:
txt = txt.replace('Thu','')
elif 'Fri' in txt:
txt = txt.replace('Fri','')
elif 'Sat' in txt:
txt = txt.replace('Sat','')
elif 'Sun' in txt:
txt = txt.replace('Sun','')
calc = int(txt) + days
while calc > days:
days = days - 1
if calc == days:
print days
break
else:
continue
但是,在变量日期中,它包含时间。我不想要时间,我只想要约会。我怎么能这样做?另外,请告诉我我的代码还有什么问题! - 谢谢
答案 0 :(得分:0)
您可以使用datetime模块仅获取当前日期。它将为您提供当前日期,甚至没有对字符串进行太多修改。
import datetime
now = datetime.date.today()
print str(now.month) + " " + str(now.day)