vbscript 如何将分钟转换为日、时、分格式
vbscript how to convert minutes to a day, hours and minutes format
您好,我有一份报告使用 vbscript
对我的字段进行逻辑处理。
该报告有一个字段是总分钟数,并且具有较大的值,例如:1950 分钟等。
我需要更新其他字段,以便将这些分钟转换为可读格式,例如 4 天 2 小时 30 分钟。我的一天是 8 小时,因为这是我的工作日。
所以 16 小时 = 2 天等等。
现在我的逻辑是这样的:
' get the total minutes
total = sum(lateminutes)
' divide the minutes by 60 to get hours
hours = Int(total) / 60
' get the division difference and convert it to minutes
minutes = Round((hours - Int(hours)) * 60)
' convert my hours to days by dividing into 8 (8 hours per day)
days = Int(hours) / 8
if Int(days) > 0 then
text = Cstr(Int(days)) & " day(s)" & " "
end if
if Int(hours) > 0 then
text = text & Cstr(Int(hours)) & " hours" & " "
endif
if Int(minutes) > 0 then
text = text & minutes & " min"
endif
testfield.Text = text
But I'm not getting the correct result, any clue?
通过整数除法 () 计算较大的单位,从您的输入值中减去较大单位的分钟 'used'。在代码中:
Option Explicit
Const cnMWD = 480 ' 8 * 60 mins in 8 hour working day
Const cnMWH = 60 ' 60 mins in 60 min working hour
Dim otp : otp = Array(0, "day(s)", 0, "hour(s)", 0, "mins")
Dim m, mm
For Each m In Array(59, 61, 479, 480, 485, 545, 2060)
mm = m
otp(0) = m \ cnMWD
m = m - otp(0) * cnMWD
otp(2) = m \ cnMWH
m = m - otp(2) * cnMWH
otp(4) = m
WScript.Echo mm, "=>", Join(otp)
Next
输出:
cscript 28798880.vbs
59 => 0 day(s) 0 hour(s) 59 mins
61 => 0 day(s) 1 hour(s) 1 mins
479 => 0 day(s) 7 hour(s) 59 mins
480 => 1 day(s) 0 hour(s) 0 mins
485 => 1 day(s) 0 hour(s) 5 mins
545 => 1 day(s) 1 hour(s) 5 mins
2060 => 4 day(s) 2 hour(s) 20 mins
您好,我有一份报告使用 vbscript
对我的字段进行逻辑处理。
该报告有一个字段是总分钟数,并且具有较大的值,例如:1950 分钟等。
我需要更新其他字段,以便将这些分钟转换为可读格式,例如 4 天 2 小时 30 分钟。我的一天是 8 小时,因为这是我的工作日。
所以 16 小时 = 2 天等等。
现在我的逻辑是这样的:
' get the total minutes
total = sum(lateminutes)
' divide the minutes by 60 to get hours
hours = Int(total) / 60
' get the division difference and convert it to minutes
minutes = Round((hours - Int(hours)) * 60)
' convert my hours to days by dividing into 8 (8 hours per day)
days = Int(hours) / 8
if Int(days) > 0 then
text = Cstr(Int(days)) & " day(s)" & " "
end if
if Int(hours) > 0 then
text = text & Cstr(Int(hours)) & " hours" & " "
endif
if Int(minutes) > 0 then
text = text & minutes & " min"
endif
testfield.Text = text
But I'm not getting the correct result, any clue?
通过整数除法 () 计算较大的单位,从您的输入值中减去较大单位的分钟 'used'。在代码中:
Option Explicit
Const cnMWD = 480 ' 8 * 60 mins in 8 hour working day
Const cnMWH = 60 ' 60 mins in 60 min working hour
Dim otp : otp = Array(0, "day(s)", 0, "hour(s)", 0, "mins")
Dim m, mm
For Each m In Array(59, 61, 479, 480, 485, 545, 2060)
mm = m
otp(0) = m \ cnMWD
m = m - otp(0) * cnMWD
otp(2) = m \ cnMWH
m = m - otp(2) * cnMWH
otp(4) = m
WScript.Echo mm, "=>", Join(otp)
Next
输出:
cscript 28798880.vbs
59 => 0 day(s) 0 hour(s) 59 mins
61 => 0 day(s) 1 hour(s) 1 mins
479 => 0 day(s) 7 hour(s) 59 mins
480 => 1 day(s) 0 hour(s) 0 mins
485 => 1 day(s) 0 hour(s) 5 mins
545 => 1 day(s) 1 hour(s) 5 mins
2060 => 4 day(s) 2 hour(s) 20 mins