The answer by @mgilson was correct until utcfromtimestamp
was removed in python >= 3.11
. New way to do this:
from pathlib import Path
from datetime import datetime, timezone
some_path = Path("/home/user/.bashrc")
datetime_utc = datetime.fromtimestamp(some_path.lstat().st_mtime, tz=timezone.utc)
>>> datetime_utc.isoformat()
'2025-01-23T17:17:08.674324+00:00'