What is a TimeTuple in Python?

PythonServer Side ProgrammingProgramming

The timetuple() method of datetime.date instances returns an object of type time.struct_time. The struct_time is a named tuple object (A named tuple object has attributes that can be accessed by an index or by name).

The struct_time object has attributes for representing both date and time fields along with a flag to indicate whether Daylight Saving Time is active.

The named tuple returned by the timetuple() function will have its year, month and day fields set as per the date object and fields corresponding to the hour, minutes, seconds will be set to zero. 

 example

import datetime
todaysDate = datetime.date.today()
timeTuple = todaysDate.timetuple()
print(timeTuple)
print(timeTuple.tm_year)

Output

This will give the output −

time.struct_time(tm_year=2017, tm_mon=12, tm_mday=28, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=362, tm_isdst=-1)
2017
raja
Published on 05-Jan-2018 13:21:08
Advertisements