0

Modify certain objects in a time_struct
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Modify certain objects in a time_struct

by robcj07 on Mon Oct 02, 2017 1:56 am

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.

robcj07
 
Posts: 9
Joined: Fri Jul 14, 2017 6:44 pm

Re: Modify certain objects in a time_struct

by adafruit_support_bill on Mon Oct 02, 2017 5:52 am

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/

adafruit_support_bill
 
Posts: 81564
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.