python生成当前事件按照这样格式输出:2022-10-25 1830
可以使用Python内置的datetime模块来生成当前时间,然后使用strftime函数将时间格式化为指定的字符串格式。
以下是一个示例代码:
import datetime
now = datetime.datetime.now()
formatted_time = now.strftime("%Y-%m-%d %H:%M")
print(formatted_time)
输出结果为:
2022-10-25 18:30
其中,%Y表示年份,%m表示月份,%d表示日期,%H表示小时,%M表示分钟。更多的格式化选项可以参考Python官方文档。
原文地址: https://www.cveoy.top/t/topic/cyqe 著作权归作者所有。请勿转载和采集!