如何用Python获取文件及图片的创建日期时间?

2026-05-16 21:280阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计930个文字,预计阅读时间需要4分钟。

如何用Python获取文件及图片的创建日期时间?

本程序使用Python和PIL库来提取图片或文件的创建日期,并在此基础上修改日期为前一天。以下是简化后的代码:

pythonfrom PIL import Image

获取图片路径imgPath='C:/Users/xx/Desktop/xxxxx.jpg'

打开图片img=Image.open(imgPath)

获取EXIF数据exif_data=img._getexif()

检查EXIF数据中是否存在创建日期if exif_data is not None: # EXIF标签中创建日期的键 tag=36867 # 36867 对应于创建日期 if tag in exif_data: # 获取创建日期 creation_date=exif_data[tag] # 修改日期为前一天 creation_date=(creation_date[0] - 1, creation_date[1], creation_date[2]) print(原始创建日期:, creation_date) print(修改后的创建日期:, creation_date) else: print(图片中没有创建日期信息。)else: print(图片没有EXIF数据。

阅读全文
标签:创建

本文共计930个文字,预计阅读时间需要4分钟。

如何用Python获取文件及图片的创建日期时间?

本程序使用Python和PIL库来提取图片或文件的创建日期,并在此基础上修改日期为前一天。以下是简化后的代码:

pythonfrom PIL import Image

获取图片路径imgPath='C:/Users/xx/Desktop/xxxxx.jpg'

打开图片img=Image.open(imgPath)

获取EXIF数据exif_data=img._getexif()

检查EXIF数据中是否存在创建日期if exif_data is not None: # EXIF标签中创建日期的键 tag=36867 # 36867 对应于创建日期 if tag in exif_data: # 获取创建日期 creation_date=exif_data[tag] # 修改日期为前一天 creation_date=(creation_date[0] - 1, creation_date[1], creation_date[2]) print(原始创建日期:, creation_date) print(修改后的创建日期:, creation_date) else: print(图片中没有创建日期信息。)else: print(图片没有EXIF数据。

阅读全文
标签:创建