# python提取邮件日期并格式化(v202111082016) import email import calendar fp = open("d:21\原创C++源码.eml") msg = email.message_from_file(fp) date = msg.get("Date") print(date) y = str(date[11:16]) y = y.replace(" ", "") # 清除空格 m = date[7:11] m = m.replace(" ", "") m = list(calendar.month_abbr).index(m) # 英文月份转数字 m = str(m) if len(m) == 1: m = "0" + m d = str(date[4:7]) d = d.replace(" ", "") if len(d) == 1: d = "0" + d ymd = str(y) + str(m) + str(d) # 定义年月日格式 print(ymd)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)