vbscript如何将分钟转换为天、小时和分钟格式

vbscript如何将分钟转换为天、小时和分钟格式,vbscript,Vbscript,您好,我有一个报告,它使用vbscript对我的字段执行逻辑 该报告有一个字段,该字段是总分钟数,并且具有较大的值,例如:1950分钟等 我需要更新其他字段,以便将这些分钟转换为可读格式,如4天2小时30分钟。我的一天是8个小时,因为这是我的劳动节 因此,16小时=2天,依此类推 现在我的逻辑是: ' get the total minutes total = sum(lateminutes) ' divide the minutes by 60 to get hours hours = I

您好,我有一个报告,它使用
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 
但我没有得到正确的结果,有线索吗


通过整数除法()计算较大的单位,从输入值中减去较大单位“使用”的分钟数。代码:

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