转换日期/时间格式

2024-05-05 23:49:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一系列采用这种格式的日期: 2021年9月10日星期五08:54:04-0500

我希望将它们转换为yyyymmdd和hhmmss(忽略-0500)。在python中有没有一种干净的方法可以有效地实现这一点


1条回答
网友
1楼 · 发布于 2024-05-05 23:49:47

你想这样吗

import time


time_string = time.strftime("%m/%d/%Y, %H:%M:%S")
#you can use colon instead of slash to change style and also 
 change position of hours minute and month etc

print(time_string)

相关问题 更多 >