Modify certain objects in a time_struct

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
robcj07
 
Posts: 9
Joined: Fri Jul 14, 2017 6:44 pm

Modify certain objects in a time_struct

Post by robcj07 »

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.

User avatar
adafruit_support_bill
 
Posts: 88112
Joined: Sat Feb 07, 2009 10:11 am

Re: Modify certain objects in a time_struct

Post by adafruit_support_bill »

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/

Locked
Please be positive and constructive with your questions and comments.

Return to “Beagle Bone & Adafruit Beagle Bone products”