[英]How can I multiply an hourly wage by a python datetime time delta
I am making a program that allows user to track how long shifts are at a work place, I have this code: 我正在编写一个程序,允许用户跟踪工作地点的轮班时间,我有以下代码:
import time
import datetime as dt
start = str(dt.datetime.now().strftime('%H:%M:%S'))
print(start)
input()
end = str(dt.datetime.now().strftime('%H:%M:%S'))
print(end)
form = '%H:%M:%S'
tdelta = dt.datetime.strptime(end,form) - dt.datetime.strptime(start,form)
pay = 10
print(tdelta)
print(tdelta * pay)
this is not the code for my actual program this is just an example I have written to test the functionality, input() is used to pause program until enter is pressed so that the duration can be calculated. 这不是我的实际程序的代码,这只是我编写的用于测试功能的示例,input()用于暂停程序,直到按下enter为止,以便可以计算持续时间。 I need the desired program to multiply 'pay' by duration, which is 'tdelta'.
我需要所需的程序将“薪水”乘以工期,即“ tdelta”。 for examply if pay is 10 and the duration is 2 hours i want the output to be 20 or £20.
例如,如果工资是10,持续时间是2个小时,我希望输出是20或20英镑。
Cheers! 干杯!
You could change 你可以改变
tdelta = dt.datetime.strptime(end,form) - dt.datetime.strptime(start,form)
to 至
tdelta = (dt.datetime.strptime(end,form) - dt.datetime.strptime(start,form)).seconds / 3600
to get tdelta in exact number of hours 在确切的小时数内获得tdelta
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.