python - 在给定的用户输入日期获取一个月的第一天和最后一天
问题描述
开始时间和结束时间的用户输入。
日期输入格式,"%Y-%m-%dT%H:%M:%S
st = 2018-10-10T00:00:00
et = 2018-03-30T23:59:59
转换后它应该看起来像:-
st1 = 2018-10-01T00:00:00 --> first day of month
et1 = 2018-06-31T23:59:59 ---> last day of month
解决方案
I find arrow
module most efficient for this kind of purpose.
import arrow
st = "2018-10-10T00:00:00"
et = "2018-03-30T23:59:59"
first_day = arrow.get(st).floor('month')
last_day = arrow.get(et).ceil('month')
print(first_day)
print(last_day)
# output
2018-10-01T00:00:00+00:00
2018-03-31T23:59:59.999999+00:00
推荐阅读
- java - 如果 Shutdown 发生,executorService 是否确保等待终止?
- java - WebClient 与 RestTemplate SSL 连接
- java - 添加一个包含 86,000 个组件的 JPanel
- java - 如何在 Java 中创建一个自动更正,让我在用户输入时替换它们?
- solr - 数组字段中 1 项的 Solr 查询语法
- import - 使用 Keras g;pu 2.2.4 版本时出现 Keras 导入错误
- exchange-server-2010 - Exchange 2010 - 从 OWA 访问邮箱时访问被拒绝
- ibm-cloud - 在尝试完成 IBM 课程时,我在运行“helm install --name bluecompute ibmcase/bluecompute-ce”时遇到问题
- javascript - 如何检查 chrome 中的 console.log 输出?需要调试一个使用 XMLHttpRequest 的 .js 文件
- node.js - Formik + Yup 号码验证