用 PowerShell 批量修正照片时间戳
用 DateTime 运算一次调整整个照片文件夹的修改时间/创建时间。
把 Get-ChildItem 通过管道传给 ForEach-Object,用 .AddHours() 给文件时间属性加上偏移量。
01命令
命令
$ Get-ChildItem 'C:\Users\me\Pictures\Camera' | ForEach-Object { $_.LastWriteTime = $_.LastWriteTime.AddHours(7); $_.CreationTime = $_.CreationTime.AddHours(7) }02作用说明
手机或相机时钟不准会让照片在所有相册应用里排序错乱,在资源管理器里逐个修改非常痛苦。FileInfo 的 CreationTime、LastWriteTime 和 LastAccessTime 都是可写的 DateTime 属性,配合 .AddHours/.AddDays 一行命令即可完成偏移。注意这只改文件系统时间戳,JPEG 内嵌的 EXIF "拍摄日期"不受影响,如需修改要另用元数据库。
03风险
04撤销
撤销
$ Repeat with a negative offset: ForEach-Object { $_.LastWriteTime = $_.LastWriteTime.AddHours(-7) }05来源
- Set-ItemProperty (Microsoft.PowerShell.Management)依据: Shows setting file property values such as timestamps; direct assignment to FileInfo properties is equivalent PowerShell syntax.
- FileSystemInfo.LastWriteTime Property依据: Documents that LastWriteTime, CreationTime and LastAccessTime on file info objects are settable DateTime properties.
最后验证: 2026-09-17 · 分类: 媒体