Show file modification time in Python
examples/python/modified.py
#!/usr/bin/env python import sys import os import time from datetime import datetime now = time.time() if len(sys.argv) < 2: exit(f"Usage: {sys.argv[0]} FILENAME") filename = sys.argv[1] mtime = os.path.getmtime( filename) print(mtime) print(now - mtime) stat = os.stat( filename) print(stat.st_mtime) date = datetime.fromtimestamp(stat.st_mtime) print(date) # mtime = os.path.getmtime( os.path.join(log_dir, thing) ) # returns something else
Published on 2019-09-21
If you have any comments or questions, feel free to post them on the source of this page in GitHub. Source on GitHub.
Comment on this post