79382098

Date: 2025-01-23 17:54:08
Score: 1
Natty:
Report link

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'
Reasons:
  • Has code block (-0.5):
  • User mentioned (1): @mgilson
  • Low reputation (0.5):
Posted by: Teque5