roboluke-tasks/app/utils/datetime.py

19 lines
400 B
Python
Raw Normal View History

2023-04-05 21:57:31 +02:00
#!/usr/bin/env python3
from datetime import datetime
2024-08-04 19:47:43 +02:00
from zoneinfo import ZoneInfo
2023-04-05 21:57:31 +02:00
def timestamp_to_date(timestamp: int) -> str:
"""Convert timestamp to date.
2024-08-04 19:47:43 +02:00
Args:
timestamp (int): Timestamp to convert.
2024-08-04 19:47:43 +02:00
Returns:
str: Date in the format YYYY-MM-DD.
"""
2024-08-04 19:47:43 +02:00
return datetime.fromtimestamp(timestamp=timestamp, tz=ZoneInfo("UTC")).strftime(
"%Y-%m-%d"
)