Python·100 questions

How to work with date and time (datetime)?

Answer
datetime.datetime.now() — current local time.
Better to store UTC: datetime.datetime.now(datetime.timezone.utc).
Parsing: datetime.datetime.fromisoformat(...).
Formatting: dt.strftime('%Y-%m-%d').
Difference: timedelta.
Was this answer helpful?

More questions in this topic

Related questions from other topics