Getting milliseconds into format? days HH:mm:ss.ms

Post Reply
Yogie
Posts: 3
Joined: Tue Apr 03, 2012 9:55 pm

Getting milliseconds into format? days HH:mm:ss.ms

Post by Yogie » Fri Apr 13, 2012 9:16 pm

Hi,

I found some code where milliseconds would be displayed in minutes and seconds... I would like to know if you can help me out with it on how to display milliseconds in days HH:mm:ss.ms?

ExposureTime (and TimeEstimate) is a value of x milliseconds...

This is what I found out already:

Code: Select all

            TimeEstimate = ExposureTime;
            TimeEstimateDays= ________________;
            TimeEstimateHours= ________________;
            TimeEstimateMinutes=(TimeEstimate/1000)/60;
            TimeEstimateSeconds=(TimeEstimate/1000)-(TimeEstimateMinutes*60);
            TimeEstimateMilliseconds= ________________;

            // days
            ________________;

            // hours
            ________________;

            // minutes
            dummy=TimeEstimateMinutes-(int(TimeEstimateMinutes/10)*10);
            // then display the minutes (the ones of it) with the value of dummy
            dummy=int((TimeEstimateMinutes-dummy)/10);
            // then display the minutes (the tens of it) with the value of dummy
            
            // seconds
            dummy=TimeEstimateSeconds-(int(TimeEstimateSeconds/10)*10);
           // then display the seconds (the ones of it) with the value of dummy
            dummy=int((TimeEstimateSeconds-dummy)/10);
           // then display the seconds (the tens of it)  with the value of dummy

            // milliseconds (the rest that would not result into a second)
            ________________;
Any idea? ::)

Thanks in advance

WinterMute
Site Admin
Posts: 1845
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: Getting milliseconds into format? days HH:mm:ss.ms

Post by WinterMute » Fri Apr 13, 2012 10:29 pm

There's a big clue in this part of the code

Code: Select all

  TimeEstimateMinutes=(TimeEstimate/1000)/60;
  TimeEstimateSeconds=(TimeEstimate/1000)-(TimeEstimateMinutes*60);
The raw time is in milliseconds which you need to divide by 1000 to get seconds, obviously you divide seconds by 60 to get minutes.

Following this logic you need to divide minutes by 60 to get hours and hours by 24 to get days. At each step we need to subtract the total time accounted for so far which is what this line is doing

Code: Select all

  TimeEstimateSeconds=(TimeEstimate/1000)-(TimeEstimateMinutes*60);
Personally I'd probably just subtract as I go, a bit like this.

Code: Select all

 Days = TimeEstimate/1000/60/60/24;
 TimeEstimate -= Days * 1000 * 60 * 60 * 24;
 Hours = TimeEstimate/1000/60/60;
 TimeEstimate -= Hours * 1000 * 60 * 60;
 Minutes = TimeEstimate/1000/60;
 TimeEstimate -= Minutes * 1000 * 60;
 Seconds = TimeEstimate/1000;
  printf("%d days, %d, hours, %d minutes and %d seconds", Days, Hours, Minutes, Seconds);
You'll need a consoleDemoInit() at the start to get printf to output text.
Help keep devkitPro toolchains free, Donate today

Personal Blog

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests