Problems with time.localtime()
Posted: Sun Oct 31, 2021 10:45 pm
I'm trying to build a clock using the Pico. Right now I am working on setting the clock, which will be done with a button on the back.
I'm using the RTC and its functions to display the time. Every time the button is pushed, I want to set the time five minutes ahead of the current time.
I thought the following would work fine:
However, adding 300 seconds to the epoch-converted time doesn't work, and I think it's because the time.localtime() function interprets every added second as an added minute instead!
Have a look at this output from my code in debugging. I've just added ONE second to the timestamp now, instead of 300.
Am I on to something here - a bug? Or am I doing something stupid?
I'm using the RTC and its functions to display the time. Every time the button is pushed, I want to set the time five minutes ahead of the current time.
I thought the following would work fine:
Code: Select all
t = rtc.datetime()
timestamp = time.mktime(t)
timestamp = timestamp + 300
rtc.datetime(time.localtime(timestamp))
Have a look at this output from my code in debugging. I've just added ONE second to the timestamp now, instead of 300.
Code: Select all
Current time tuple
(2021, 10, 31, 6, 23, 44, 18, 0)
Current timestamp
1635661424
Added one second
1635661425
New time tuple
(2021, 10, 31, 6, 23, 45, 6, 304)