From stat().st_mtime to datetime?
You can use datetime.datetime.fromtimestamp
, i.e.
from datetime import datetime, timezone
...
stat_result = path.stat()
modified = datetime.fromtimestamp(stat_result.st_mtime, tz=timezone.utc)
print('modified', modified)
This works for me if you want a readable string:
import datetime
mtime = path.stat().st_mtime
timestamp_str = datetime.datetime.fromtimestamp(mtime).strftime('%Y-%m-%d-%H:%M')