程序员!我有一个关于如何在我的钢琴独奏会之前做一个倒计时日历的问题;只是作为一个有趣的副业。因此,牢记这一点,我创建了以下代码:
#!/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但是,在可变日期中,它包含时间。我不想要时间我只想要日期。我怎么能这样做呢?另外,请告诉我我的代码还有什么问题!-谢谢
发布于 2016-03-16 03:54:32
您可以使用datetime模块仅获取当前日期。它将为您提供当前日期,甚至不需要对字符串进行如此多的修改。
import datetime
now = datetime.date.today()
print str(now.month) + " " + str(now.day) https://stackoverflow.com/questions/36020595
复制相似问题