首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >倒计时日历,它告诉你离CPU启动还有多少天

倒计时日历,它告诉你离CPU启动还有多少天
EN

Stack Overflow用户
提问于 2016-03-16 03:38:43
回答 1查看 80关注 0票数 1

程序员!我有一个关于如何在我的钢琴独奏会之前做一个倒计时日历的问题;只是作为一个有趣的副业。因此,牢记这一点,我创建了以下代码:

代码语言:javascript
复制
#!/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

但是,在可变日期中,它包含时间。我不想要时间我只想要日期。我怎么能这样做呢?另外,请告诉我我的代码还有什么问题!-谢谢

EN

回答 1

Stack Overflow用户

发布于 2016-03-16 03:54:32

您可以使用datetime模块仅获取当前日期。它将为您提供当前日期,甚至不需要对字符串进行如此多的修改。

代码语言:javascript
复制
import datetime

now = datetime.date.today()
print str(now.month) + " " + str(now.day)  
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36020595

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档