Hello,
I'm working with the time library in order to compare dates in Python. I only want to compare whether the current time has reached a certain hour or not, let's say 22h.
I acquire the date and time with time.localtime() and I can specify the 22h comparison with time.strptime(..) but the problem is I must specify the whole date and time so I would like you to tell me how can I use the time.localtime() function to set all objects of the time_struct and just modify the hour to 22h so as to make the comparison no matter what time I run this program.
Thanks.
Modify certain objects in a time_struct
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88112
- Joined: Sat Feb 07, 2009 10:11 am
Re: Modify certain objects in a time_struct
The datetime object has a .time member. And that has members for the hours minutes and seconds etc. Each of those can be individually manipulated and/or compared.
https://pymotw.com/2/datetime/
https://pymotw.com/2/datetime/
Please be positive and constructive with your questions and comments.