python - 从输入中取一个日期,看看它是从今天开始的天数
问题描述
我正在尝试制作一个程序,该程序采用用户以“yyyy mm dd”格式输入的日期,并查看该输入从今天开始的天数。我不知道该怎么做,但如果你能提供帮助,那就太好了。
input("This is a function to find the difference between today and a date
you enter. Enter the date in this format: 'yyyy mm dd' ")
解决方案
这应该工作
import datetime
today = datetime.date.today()
year = int(input('Enter a year')) #input the needed year
month = int(input('Enter a month')) #input the needed month
day = int(input('Enter a day')) #input the needed day
neededdate = datetime.date(year, month, day)
days_remaining = neededdate - today
print(days_remaining.days)
我编辑输入日期、月份和年份。
推荐阅读
- angular - 以角度将多个值从服务返回到组件
- node.js - 如何为自定义类验证器验证装饰器强制执行某些执行顺序
- node.js - 有没有什么办法可以不使用任何第三方图片优化导出Next JS APP?
- java - 从自定义 gradle 插件中读取 Spring Properties 文件
- async-await - 等待来自 job.await() 的数据在 Composable 内部使用
- graphql - 使用 gaphql faker 伪造 graphql api 似乎没有按 id 查询字段
- python - 如何将模型视为可视化?
- emacs - org-latex-preview 错误:请调整 org-preview-latex-process-alist 的 luamagic 部分
- python-3.x - 如何根据查询集中的值为对象分配排名
- .htaccess - htaccess 内容协商在 LiteSpeed 服务器上不起作用