Datetime.time() method in Python

Method Name:

time

 

Method Signature:

time()

 

Method Overview:

The time() instance method of the python datetime class returns a time object.

Using this method only the time information excluding the date information is retrieved from a datetime object.

Note that the time object created is "naive" object which does not possess any time zone information.

 

Example:

import datetime

 

# Create a datetime object

datetimeObject = datetime.datetime.today()

 

# Retrieve only the time instance from datetime object

timeObject = datetimeObject.time()

 

# Print the datetime object

print(datetimeObject)

 

# Print the date object

print(timeObject)

 

Output:

2017-02-13 18:43:57.338090

18:43:57.338090

 

 


Copyright 2024 © pythontic.com