Converting Times From and To the Number of Seconds Elapsed

Times can be stored as the number of elapsed seconds. This value is used for comparing times and to store times as long integer value instead of a string.

To convert a time string to elapsed seconds, call the time to seconds function, time_tosec():

long time_tosec(time_stp, format_stp)
 
UCHAR *time_stp;
/* Time string to convert
*/
UCHAR *format_stp;    
/* Time format string to use
*/

time_tosec() returns the number of seconds elapsed for the specified time as a long integer. This number is calculated by the formula

elapsed seconds = 3600 * hours + 60 * minutes + seonds

To convert the number of seconds elapsed back to a time string, call the time from seconds function, time_frsec():

int time_frsec(time_stp, elapsed_sec, format_stp)
 
UCHAR *time_stp;
/* Time string to store time in
*/
long elapsed_sec;
/* Elapsed seconds to convert
*/
UCHAR *format_stp;    
/* Time format string to use
*/

time_frsec() places the resulting time string, formatted according to the specified format string, in the pointer to the time string passed in the call. Note that you must allocate memory for the string used to receive the formatted time string. This string must be long enough to accept a time string of the specified format.


Home Contents Previous Next