Jump to content
Sign in to follow this  
brk303

Duration as string ?

Recommended Posts

Posted (edited)

Hello everyone,

 

I would like to display a user friendly string describing duration.

So that it would produce strings along the line of :

 

"33 milliseconds"

"15 seconds"

"1 minute and 5 seconds"

"1 hour and 3 minutes"

"1 day and 6 hours and 15 minutes"

 

Or something similar.

EDIT:

Also ,notice that it would not say "10 days and 32 seconds", nor "2 months and 12 minutes" because that's not how people describe time.

IOW, if you get into hours, the milliseconds don't matter any more, if you get into days, the seconds don't matter, if you get into months, the minutes don't matter, and so on.

 

I could code it myself, but I wonder if there is already an implementation somewhere that I am not aware of.

 

Thanks for your time.

Edited by brk303

Share this post


Link to post
Posted (edited)

SecondsToHumanReadableString in my dzlib. There are probably others which I am not aware of.

I just noticed that you wanted milliseconds support. My function does not support these.

Edited by dummzeuch
  • Like 2

Share this post


Link to post

If you are on Windows you can check GetDurationFormatEx in Winapi

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×