Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

type casting /converting seconds to a days hours minutes seconds

  Asked By: Nicole    Date: Jan 18    Category: Java    Views: 1309
  

i am trying to covert second to days hours minutes and seconds i
am trying to calculate the time a page takes to download so number of
bits / connection speed bits per second


this is the code i have written to do it but it needs me to type cast
any help appreciated or if there is a better way to do this please
help .

public void SecondsConverter()
{
double days;
long Ldays;
double hours;
long Lhours;
double minute;
long Lminute;
long Lsecond;

Double calcspeed;
calcspeed.=Speed;

days=calcspeed/86400;
if(days<0)
Ldays=days.longValue();
else
Ldays=00;


calcspeed=calcspeed-(Ldays*86400);

hours=Speed/3600;
if(hours<0)
Lhours=hours.longValue();
else
Lhours=00;

calcspeed=calcspeed-(Lhours*3600);

minute=Speed/60;

if(minute<0)
Lminute=minute.longValue();
else
Lminute=00;

calcspeed=calcspeed-(Lminute*60);

Lsecond=calcspeed.longValue();


String ConnSpeed= Long.toString(Ldays)
+":"+Long.toString(Lhours)+":"+Long.toString(Lminute)
+":"+Long.toString(Lsecond)+"(Days:Hours:Minutes:Secs)";

}

Share: 

 

1 Answer Found

 
Answer #1    Answered By: William Bouchard     Answered On: Jan 18

// casting in java:

long Ldays = 0L;
double days  = 5.0;
Ldays = (long)days;

// cast primitive to String:

String s = "" + Ldays;

 




Tagged: