当前位置: 首页 > 图文教程 > 网络编程 > 编程10000问 > 如何计算下载一个文件需要多长时间?

编程10000问
如何编制一个产生随机密码的函数?
如何利用当前时间生成随机函数?
如何做一个密码“生成器”?
如何做一个随机密码产生器?
如何将产生的密码记录并发送给用户并通过点击链接激活?
如何取回已忘记的密码?
如何让用户也能修改密码?
如何在线更改密码?
如何计算出当前日期属于定义时间段内的第几星期?
如何验证日期输入是否正确?
如何制作一个倒计时的程序?
如何制作一个Web日程安排表?
如何在网站中插播广告?
如何拒绝同一张表单被多次提交?
不用Global.asa也能实现统计在线人数吗?
如何防范利用刷新来“作弊”的计数器?
如何防止计数器刷新计数?
如何让计数器只对新进用户计数?
如何实时获知多少人在线?
如何最准确地统计在线用户数?

编程10000问 中的 如何计算下载一个文件需要多长时间?


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 33 ::
收藏到网摘: n/a

<%
Function DownloadTime(intFileSize, strModemType)
Dim TimeInSeconds, ModemSpeed, strDownloadTime, AppendString
Dim intYears, intWeeks, intDays
Dim intHours, intMinutes, intSeconds
intYears = 0
intWeeks = 0
intDays = 0
intHours = 0
intMinutes = 0
intSeconds = 0
strDownloadTime = ""
Select Case strModemType
Case "Cable"
ModemSpeed = 400000
Case "56kbps"
ModemSpeed = 7000
Case "33.6kbps"
ModemSpeed = 4200
Case "28.8kbps"
ModemSpeed = 3600
End Select
TimeInSeconds = int(intFileSize / ModemSpeed)
'
准确地说,1年=365.25.
If (Int(TimeInSeconds / 31471200) <> 0) Then intYears = Int(TimeInSeconds / 31449600)
If ((Int(TimeInSeconds / 604800) Mod 52) <> 0) Then intWeeks = Int(TimeInSeconds / 604800) Mod 52
If ((Int(TimeInSeconds / 86400) Mod 7) <> 0) Then intDays = Int(TimeInSeconds / 86400) Mod 7
If TimeInSeconds >= 3600 Then intHours = Int(TimeInSeconds / 3600) Mod 24
If TimeInSeconds >= 60 Then intMinutes = Int(TimeInSeconds / 60) Mod 60
If TimeInSeconds >= 0 Then intSeconds = Int(TimeInSeconds) Mod 60
If intYears <> 0 Then
strDownloadTime = strDownloadTime & intYears & "
" & AppendString & ", "
End If
If intWeeks <> 0 Then
strDownloadTime = strDownloadTime & intWeeks & "
" & AppendString & ", "
End If
If intDays <> 0 Then
strDownloadTime = strDownloadTime & intDays & "
" & AppendString & ", "
End If
If intHours <> 0 Then
strDownloadTime = strDownloadTime & intHours & "
小时" & AppendString & ", "
End If
If intMinutes <> 0 Then
strDownloadTime = strDownloadTime & intMinutes & "
" & AppendString
End If
If ((intYears = 0) And (intWeeks = 0) And (intDays = 0) And (intHours = 0)) Then
If intMinutes > 0 Then
strDownloadTime = strDownloadTime & ", " & intSeconds & "
" & AppendString
Else
strDownloadTime = strDownloadTime & intSeconds & "
" & AppendString
End If
End If
DownloadTime = strDownloadTime
End Function
%>
<html>
<body>
撼雪喷云提示:您下载这个文件一共花费了<%=DownloadTime(123456,Cable)%>.
</body></html>

[1]