Python 3 Date and Time Manipulation: Examples

Last updated:

WIP Alert This is a work in progress. Current information is correct but more content will probably be added in the future.

Build a datetime object manually

from datetime import datetime

# year, month, day, hours, minutes, seconds ...
obj = datetime(2016,5,10,12,30,0,0)

with timezone information:

from datetime import datetime,timezone,timedelta

# UTC+03:00
val tz = timezone(timedelta(hours=3))

obj = datetime(2016,5,10,12,30,0,0, tzinfo=tz)


ISO format


See Also:

Dialogue & Discussion