简体   繁体   中英

Divide 24hours in user inputted number

I am writing a python code to resolve a problem.Guide me to write a simple code for it.

The problem is.. I have to show which shift number is going on, comparing with using the current time. If there are 3 shifts in 24hrs then the shifts are like morning 7 to 3:00 From 3:00 to night 11:00 and the last shift will be end at 7:00 in next morning.

How can I show the current shift nunber according to current time when user gets login

Here is some quick example:

import datetime as dt

hour = dt.datetime.now().hour
shiftNr = 0

if ( hour > 6 and hour < 15 ):
    shiftNr = 1
elif ( hour > 14 and hour < 23 ):
    shiftNr = 2
else:
    shiftNr = 3

print( "Shift number is: " + str(shiftNr) )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM