如何计算下载一个文件需要多长时间?

所属分类: 网络编程 / 编程10000问 阅读数: 685
收藏 0 赞 0 分享

<%
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]

更多精彩内容其他人还在看

如何实现人民币的大写转换?

如何实现人民币的大写转换?
收藏 0 赞 0 分享

怎样给文件加密最安全?

怎样给文件加密最安全?
收藏 0 赞 0 分享

如何用Access加密页面?

如何用Access加密页面?
收藏 0 赞 0 分享

为什么用磁盘序列号加密过的代码不能被复制安装?

为什么用磁盘序列号加密过的代码不能被复制安装?
收藏 0 赞 0 分享

如何根据用户银行帐户余额的多少进行显式的提交或终止?

如何根据用户银行帐户余额的多少进行显式的提交或终止?
收藏 0 赞 0 分享

如何获知所有的Cookie?

如何获知所有的Cookie?
收藏 0 赞 0 分享

如何提示用户打开Cookie?

如何提示用户打开Cookie?
收藏 0 赞 0 分享

如何刪除客户端的Cookies?

如何刪除客户端的Cookies?
收藏 0 赞 0 分享

如何让用户再次访问我的网站时不需再提交相关信息?

如何让用户再次访问我的网站时不需再提交相关信息?
收藏 0 赞 0 分享

如何用Cookie进行登录验证?

如何用Cookie进行登录验证?
收藏 0 赞 0 分享
查看更多