gpt4 book ai didi

python:如何更改 Outlook 获取创建时间格式?

转载 作者:行者123 更新时间:2023-12-01 04:00:16 27 4
gpt4 key购买 nike

我想更改 Outlook 创建时间格式。

for message in sub.Items:
subject = message.subject
body = message.body
sendTime = message.CreationTime

我收到使用 message.CreationTime 的消息 creationTime。当我打印 sendTime 时,结果是 04/15/16 17:22:29。所以我使用strftime来更改日期格式,但它不起作用。

我在源代码中导入了这样的库。

import win32com.client
from datetime import datetime, date, time
import string
import pymysql

但是发生了错误:

Traceback (most recent call last):
File "D:\20_log\outlook\outlook.py", line 164, in <module> main()
File "D:\20_log\outlook\outlook.py", line 161, in main get_outlook_message()
File "D:\20_log\outlook\outlook.py", line 56, in get_outlook_message
sendTime.strftime('%H:%M:%S')
AttributeError: strftime

如何更改 Outlook creationTime 格式?

最佳答案

由于(根据您的评论)sendTime是一个字符串,您可以将其解析为 time.struct_time使用 time.strptime(),然后可以像您尝试的那样使用 time.strftime() 对其进行格式化。

import time

sendTime = '04/15/16 17:22:29' # example value of message.CreationTime

# parse sendTime into a time.struct_time
sendTime_st = time.strptime(sendTime, '%m/%d/%y %H:%M:%S')

# format the returned struct_time into the desired format
print(time.strftime('%H:%M:%S', sendTime_st))
# another example
print(time.strftime('%a, %m-%b-%y at %H:%M:%S', sendTime_st))

输出:

17:22:29
Fri, 04-Apr-16 at 17:22:29

关于python:如何更改 Outlook 获取创建时间格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36688622/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com