LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

"convert to time"

I need to convert a number of seconds into hours, minutes, & seconds.  Is there a canned function for this?  If not, does anyone have sample code?
0 Kudos
Message 1 of 5
(3,377 Views)
Erroneous duplicated post

Message Edited by Roberto Bozzolo on 07-13-2005 11:44 PM



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 5
(3,371 Views)
Erroneous duplicated post

Message Edited by Roberto Bozzolo on 07-13-2005 11:44 PM



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 3 of 5
(3,371 Views)
Erroneous duplicated post

Message Edited by Roberto Bozzolo on 07-13-2005 11:45 PM



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 5
(3,370 Views)
There is no built-in function that does it but this is easy to obtain:
1. Divide number of seconds by 3600.0: integer part is hours
2. Divide the rest of the operation by 60.0: integer part is minutes
3. The rest of the division is seconds.
 
In code:
 
double  tt, hh, mm, ss;
 
tt = 17257.0;
DebugPrintf ("%.0f seconds are equivalent to ", tt);
modf (tt / 3600.0, &hh);
tt = fmod (tt, 3600.0);
modf (tt / 60.0, &mm);
ss = fmod (tt, 60.0);
DebugPrintf ("%.0fh %.0fm %.0fs\n", hh, mm, ss);
 
If on the contrary your seconds are time from midnight and you want to obtain the clock corresponding to this, you can rely on some SDK functions to obtain it.
 
1. Divide your seconds by 86400.0 (seconds in a day)
2. Pass the result to VariantTimeToSystemTime: it will return a SYSTEMTIME structure
3. wHour, wMinute and wSecond fields of the structure are what you want
 
Again, in code:
 
#include <windows.h>
#include <oleauto.h>
 
int  err;
double  tt, secs;
SYSTEMTIME  dh;
 
secs = 17257.0;
tt = secs / 86400.0;
 
err = VariantTimeToSystemTime (tt, &dh);
 
DebugPrintf ("%.0f seconds are equivalent to %.0fh %.0fm %.0fs\n", secs,
   dh.wHour, dh.wMinute, dh.wSecond);
 

Message Edited by Roberto Bozzolo on 07-14-2005 12:03 AM



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 5 of 5
(3,373 Views)