We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


Converting a float to minutes and seconds

DanBAtkinson asked
Medium Priority
Last Modified: 2012-05-05
Hey there!

This is a quick question really.

I have a float (lets say 520) which represents the number of seconds in a journey.

I'm wanting to give a time for that journey in seconds (in the format xx minutes xx seconds) so in this case (520 seconds), it would be "8 minutes 40 seconds".

Are there a few simple lines of code that can do this please?

I've had a Google at it but I'm mostly getting back API stuff on Time and Date.

Thanks in advance.
Watch Question

long l = 520;

String time = ""+(l/60)+"m "+(l%60)+"s";

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Top Expert 2016

int mins = (int)(f / 60);
int secs = (int)(f % 60);
oh, You said float, then simply cast it to long:

long l = (long) _any_float_here_
Top Expert 2016
Formatted per your style:

System.out.printf("%d minutes %d seconds\n", (int)(f /60), (int)(f % 60));


I'd like to split the points here to CEHJ because they supplied an answer which was in the style I asked and it's in one line.

But I'll also award points to StillUnAware for the speed and the fact that his is also correct.

100 to StillUnAware as an assist
400 to CEHJ for the correct answer
Top Expert 2016

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.