A guide to understanding the datetime module in Python.

Time

This module helps deal with timestamps. The time class has attributes like hour, minute, second and microsecond.

>>> import datetime

Let’s create a timestamp. The arguments are in the following order — hour, minutes, seconds, microseconds, time zone information.

>>> t1 = datetime.time(6, 4, 2)

>>> print(t1)
06:04:02

As you can there are various methods which can be used.

>>> t1.hour
6

>>> t1.minute
4
>>> t1.microsecond
0
>>> print(t1.tzinfo)
None

We can also get the minimum and maximum time we can have.

>>> print(datetime.time.min)
00:00:00

>>> print(datetime.time.max)
23:59:59.999999

#programming #coding #python3 #datetime #python #datetime module in python

Datetime module in Python
1.60 GEEK