[Python 3的API reference说imaplib的Internaldate2tuple解析了IMAP4 INTERNALDATE字符串,但我无法在任何地方找到该信息的确切含义。反向函数(Time2Internaldate)似乎产生了这些INTERNALDATE字符串之一,但对于Internaldate2tuple字符串来说显然不够好。这是一个错误,imaplib的功能不应该相互兼容吗?
除了正则表达式和某些strftime以外,还有其他方法可以解析内部日期吗?
from time import localtime
internaldate = imaplib.Time2Internaldate(localtime())
print("Coded: " + internaldate)
coded = imaplib.Internaldate2tuple(internaldate.encode('ascii'))
if coded == None:
print("Wrong format")
else:
print("Success")
internaldate = internaldate.replace('"', '')
print("Coded: " + internaldate)
coded = imaplib.Internaldate2tuple(internaldate.encode('ascii'))
if coded == None:
print("Wrong format")
else:
print("Success")
输出:
Coded: "14-Dec-2019 15:15:47 +0200"
Wrong format
Coded: 14-Dec-2019 15:15:47 +0200
Wrong format