up vote 0 down vote favorite II have a time, in seconds, which has the possibility to be very large. I wish to convert said time into the "appropriate" rounded, readable format.
I already have code which achieves this, however it's not very efficient (and contains a whole bunch of magic numbers):
String readable = decayTime + " minutes";
if(decayTime > 60)
{
decayTime /= 60;
readable = decayTime + " hours";
if(decayTime > 24)
{
decayTime /= 24;
readable = decayTime + " days";
if(decayTime > 365)
{
decayTime /= 365;
readable = decayTime + " years";
if(decayTime > 1000000)
{
decayTime /= 1000000;
readable = decayTime + "mn years";
if(decayTime > 1000)
{
decayTime /= 1000;
readable = decayTime + "bn years";
}
}
}
}
Apart from switching out the magic numbers, I can't personally think how to make it better.
What I am asking is essentially what would be a better approach to this, or is there something in-built which could help?