0

I'm working on my script to set the time in each time when I call the GoRight function.

I'm trying to set the time to 1 hour forward in each time when I call the GoRight function, but it would not let me to change from the current time in the setLabel method.

When I try this:

def GoRight(self):

# Set the date and time row
current_time = time.time() # now (in seconds)
half_hour = current_time + 60*30  # now + 30 minutes
one_hour = current_time + 60*60  # now + 60 minutes

for t in [current_time,half_hour,one_hour]:
    if (0 <= datetime.datetime.now().minute <= 30):
        self.getControl(346).setLabel(time.strftime("%I" + ":30%p",time.localtime(t)).lstrip("0"))
    else:
        self.getControl(346).setLabel(time.strftime("%I" + ":00%p",time.localtime(t)).lstrip("0"))

It will show "5:00PM or 5:30PM in each time when I call the function. It will only show the time from my current time. I want to add it to one hour forward in each time when I call the function.

I'm trying to set the time to one hour forward in each time when I call the function, example: I call the function to use the setLabel method to add the time to one hour forward in each time 5:30PM, 6:00PM, 6:30PM, 7:00PM, 7:30PM...etc

Can you please show me an simple example of how I can set the time to one hour forward in each time when I use to call the function?

Rob
  • 189
  • 1
  • 3
  • 14
  • Do you mean you want to change the system's time? Or are you asking how to do time arithmetic? – wallyk May 11 '15 at 15:54
  • Yes I want to change the system's time when writing the code in python. Could you please show me how I could do that to add the one hour forward time in each time when I call the function so if I have the time `6:30PM` in the label, i want to change it to `7:00PM`, then `7:30PM`, `8:00PM`, `8:30PM`, `9:00PM`...etc in each time I call the GoRight function. Do you know how I could do that? – Rob May 11 '15 at 15:57
  • Not sure - what you are trying to do - but would timedelta help? try looking at it. – gabhijit May 11 '15 at 16:02
  • I don't think the average user would appreciate you changing their system time. To be clear, that's the thing that dictates what the clock on their start menu displays. If you're just trying to do arithmetic on time values and display them in your application, you don't need to change the system time. – Kevin May 11 '15 at 16:03
  • Well, the program will have to run with privileges sufficient to change the system time, and the program will need to call [`time.clock_settime()`](https://docs.python.org/3/library/time.html?highlight=settime#time.clock_settime). – wallyk May 11 '15 at 16:08
  • @Kevin: What is a "start menu display"? – wallyk May 11 '15 at 16:08
  • @wallyk i think he mean time widget on task bar in UI of target system. – Reishin May 11 '15 at 16:10
  • guys, I'm talking about writing the python code to add the time to one hour forward in each time I call the function, not about change the system time. – Rob May 11 '15 at 16:12
  • Well, which is it? In the second comment, you (Rob) write "Yes I want to change the system's time". Now you write you don't want to change the system time. – wallyk May 11 '15 at 16:13
  • An [MCVE](http://stackoverflow.com/help/mcve) might be useful in clearing up this confusion. – Kevin May 11 '15 at 16:15
  • @wallyk, sorry you was confused me. I thought you meant about writing the code to change the system time. I want to print the time to one hour forward to each time i call the function, how i can do that? – Rob May 11 '15 at 16:16
  • do you know how i can create the time to one hour forward to each time i call the function, do you know how i can do that? – Rob May 11 '15 at 16:29
  • 1
    @Rob it looks like you need something like [this](http://stackoverflow.com/questions/100210/what-is-the-standard-way-to-add-n-seconds-to-datetime-time-in-python) – Reishin May 11 '15 at 16:45
  • @Reishin how i can add the 30 mins to each time i call the function? can you show me an example please? – Rob May 11 '15 at 17:14

0 Answers0