1# note: test.txt can also be a file path
2import os.path, time
3print("Last modified: %s" % time.ctime(os.path.getmtime("test.txt")))
4print("Created: %s" % time.ctime(os.path.getctime("test.txt")))
1import os, time
2# Get file's Last modification time stamp only in terms of seconds since epoch
3modTimesinceEpoc = os.path.getmtime(filePath)
4# Convert seconds since epoch to readable timestamp
5modificationTime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(modTimesinceEpoc))
6print("Last Modified Time : ", modificationTime )
1import os
2import platform
3
4def creation_date(path_to_file):
5 """
6 Try to get the date that a file was created, falling back to when it was
7 last modified if that isn't possible.
8 See http://stackoverflow.com/a/39501288/1709587 for explanation.
9 """
10 if platform.system() == 'Windows':
11 return os.path.getctime(path_to_file)
12 else:
13 stat = os.stat(path_to_file)
14 try:
15 return stat.st_birthtime
16 except AttributeError:
17 # We're probably on Linux. No easy way to get creation dates here,
18 # so we'll settle for when its content was last modified.
19 return stat.st_mtime