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. 


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


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)
Updated on 19-Feb-2020 05:27:35