Need Assistance?

support@tutorialshub.in

Virtual Environments and Packages

requirements and dependency locking

ADVERTISEMENT
Python Free Lesson
5 min read
ADVERTISEMENT

Dates, times and time zones

The datetime module provides dates, times, combined date-times and durations. Time handling becomes difficult when an application serves users in multiple regions or stores timestamps across systems.

Prefer timezone-aware timestamps

A naive datetime does not contain enough information to identify its timezone. For application events that represent a real point on a global timeline, use timezone-aware values and establish a clear storage convention, commonly UTC.

Duration is different from a date-time

timedelta represents a duration. A calendar date-time represents a point in time. Keep those concepts separate when calculating deadlines, scheduling jobs or displaying dates.

Practice: parse an ISO timestamp, convert it to UTC and calculate a two-hour deadline.

ADVERTISEMENT