python - 在python中以日期时间格式获取当前小时和分钟
问题描述
我想在 python 中以特定格式获取当前时间:
- 'H:M' 格式
- 'datetime.time' 类
这是因为我试图以这种确切的格式将当前时间与另一个时间进行比较,我从一个 excel 文件中获取。
当我尝试明显的:
>>> from datetime import datetime
>>> now = datetime.now()
>>> current_time = (now.hour, now.minute)
>>> current_time > other_time
(“其他时间”例如“datetime.time(8, 30)”)
我得到:
TypeError: '>' not supported between instances of 'datetime.time' and 'tuple'
我尝试了各种各样的东西并搜索了所有东西,但找不到任何适合我的东西,它总是归结为不受支持的实例,如 'tuple' 'str' 或其他。
非常感谢您的帮助。
解决方案
推荐阅读
- python - keras中的输入形状RNN
- azure-cosmosdb - Cosmos SDK 3.0 中的 FeedOptions.PopulateQueryMetrics
- c++ - 为什么函数中b的第一个打印语句打印的是5而不是6?
- blazor-server-side - Blazor EditForm 缺少电子邮件和电话?
- azure - 微软 Azure SQL 数据同步
- php - 在 ARM CPU 上升级 PHP
- python - 为什么我在 response_moedel 中不使用 List 时会抛出错误?
- javascript - 如何在水平堆积条形图中显示条形值
- amazon-web-services - SCP 不会找到文件,即使它存在
- python - SQLAlchemy - 使用旧对象的新会话时对象“已存在于此会话中”