James James - 2 months ago 8x
Python Question

How do I determine if current server time isn't within a specified range using Python ?

I need to check in Python if the current time on the server isn't in the time range of 22:00PM - 04:00AM.

What is the correct way to write this code ?

Thanks !


Try this below:

import time
def isWithinRange():
    hour = time.localtime(time.time()).tm_hour
    return hour >= 22 or hour <= 4