Skip to content

Instantly share code, notes, and snippets.

@keewon
Created June 13, 2017 06:34
Show Gist options
  • Save keewon/f710988f44b546a09b85ff6525d3e767 to your computer and use it in GitHub Desktop.
Save keewon/f710988f44b546a09b85ff6525d3e767 to your computer and use it in GitHub Desktop.
import os
from datetime import datetime
# Downloaded files from Google Photo have time in UTC.
# I want to change them to use my local timezone.
tzdiff = 3600 * 9 # my timezone is +09:00
for f in os.listdir('.'):
if '.JPG' in f or '.jpg' in f:
stinfo = os.stat(f)
x = datetime.fromtimestamp(stinfo.st_mtime).strftime("%Y%m%d_%H%M%S")
print f, stinfo.st_mtime, stinfo.st_atime, x
# if you want to embed date into filename
# os.system('mv "%s" "%s_%s"' % (f, x, f)) # TODO: better rename function
# if you want to change atime and mtime
#os.utime(f, (stinfo.st_atime + tzdiff, stinfo.st_mtime + tzdiff))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment