Time conversion in C

M

moni

This is all in C:

I have 2 time values:

System time and an input from the user.

1) System time is in the form of seconds from 1/1/1970 calculated by
using

time_t secs;
SYSTEMTIME stime;

time(&secs);

2) The input from the user is in form hr:min:sec which is a string
value.

But the seperate values have been obtained by using

sscanf(storedTimeValue, "%d:%d:%d", &hour,&minutes,&seconds);

So now I have 3 integer values for hour,minutes and seconds.

3) I have a function which calculates the time difference between 2
time values,
but both these time values need to be seconds from 1/1/1970.

Is there any way by which,I could convert the user given time into time
in seconds from 1/1/1970,
so that I can get the difference between the system time and the user
given time.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

moni said:
This is all in C:

So why ask in a C# group ?
I have 2 time values:

System time and an input from the user.

1) System time is in the form of seconds from 1/1/1970 calculated by
using

time_t secs;
SYSTEMTIME stime;

time(&secs);

2) The input from the user is in form hr:min:sec which is a string
value.

But the seperate values have been obtained by using

sscanf(storedTimeValue, "%d:%d:%d", &hour,&minutes,&seconds);

So now I have 3 integer values for hour,minutes and seconds.

3) I have a function which calculates the time difference between 2
time values,
but both these time values need to be seconds from 1/1/1970.

Is there any way by which,I could convert the user given time into time
in seconds from 1/1/1970,
so that I can get the difference between the system time and the user
given time.

This is not the right forum.

But you can stuff your integer values into a struct tm
and convert it to a time_t with the mktime function.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top