Using C#.Net code
private void CalculateDownloadTime(double fileSizeMB,double fileSizeKB,int speed,ref int timeHour,ref int timeMinute,ref int timeSec)
{
double downloadTime = 0;
if (fileSizeMB != 0)
{
downloadTime = (fileSizeMB * Constant.FILE_SIZE_KB * 8.192) / speed;
}
else if (fileSizeKB != 0)
{
downloadTime = (fileSizeMB * 8.192) / speed;
}
timeHour = Convert.ToInt32(downloadTime) / 3600;
timeMinute = (Convert.ToInt32(downloadTime) % 3600) / 60;
timeSec = Convert.ToInt32(downloadTime) % 60;
}
Example to call above function:
int timeHour =0;
int timeMinute =0;
int timeMinute =0;
CalculateDownloadTime(30,0,56, ref timeHour, ref timeMinute, ref timeMinute);
Using Java Script
<script type="text/javascript">
var speeds = new Array(
new Array("9.6 Modem", "9.6"),
new Array("14.4 Modem", "14.4"),
new Array("19.2 Modem", "19.2"),
new Array("28.8 Modem", "28.8"),
new Array("33.6 Modem", "33.6"),
new Array("56 Kb Modem", "56"),
new Array("Single Channel ISDN (64Kbps)", "64"),
new Array("Dual Channel ISDN (128Kbps)", "128"),
new Array("Asymmetric DSL (ADSL)", "384"),
new Array("Single-pair HDSL (S-HDSL)", "768"),
new Array("Consumer DSL (CDSL)", "1024"),
new Array("T1", "1544"),
new Array("HDSL", "1544"),
new Array("T3", "46080"),
new Array("Very high-speed DSL (VDSL)", "52224"),
new Array("OC1", "53248"),
new Array("100 Base-T (fast ethernet)", "102400"),
new Array("ATM", "158720"),
new Array("OC3", "159744"),
new Array("1000 Base-T", "1024000")
);
function compute (form, scale)
{
if (form.size == null form.size.length == 0)
{
alert("Please enter a valid filesize.");
return;
}
var size = parseFloat(form.size.value);
for (var i = 1; i <= speeds.length; i++)
{
var time = size * scale * 8.192 / speeds[i - 1][1];
var hours = Math.floor(time / 3600);
var minutes = Math.floor((time % 3600) / 60);
var seconds = Math.floor(time % 60);
form[i + "hour"].value = hours;
form[i + "minute"].value = minutes;
form[i + "second"].value = seconds;
}
}
</script>
Example to call above (compute) function: For file Size MB --> compute(30,1024)
For file size KB --> compute(30,1)
Read more...