Getting System time (time.h)

Hi,

I can’t seem to get the system time. I am using a connectcore 7U on the development kit. The code is straightforward, and works normally on windows, linux, etc:

void printCurTime()
{
time_t rawtime;
time ( &rawtime );
printf ( “The current local time is: %s”, ctime (&rawtime) );
}

The result is always the same:

The current local time is: Thu Jan 1 00:00:00 1970
The current local time is: Thu Jan 1 00:00:00 1970
The current local time is: Thu Jan 1 00:00:00 1970
The current local time is: Thu Jan 1 00:00:00 1970
The current local time is: Thu Jan 1 00:00:00 1970
The current local time is: Thu Jan 1 00:00:00 1970

This is not what I would expect. Even if the clock was not set on the board (and defaulted to Jan 1 1970 on power up), I would still expect it to increment!

Does anyone have a solution to getting system time?

Thanks in advance,
-Trevor

HI,
You have to put in a handler to get the system time to run. have a look in the API reference for:

BOOLEAN naTimeFunctionInstall(user_time_func_t time_function, void * user_data);

If you still have problems post another message and I think I have some sample code I can get tommorow

Do you how to set the local time and date ?

Hello

Here is some code that I threw together a while ago. It may be crude that it might give you a start.

I am throwing in the root.c that I used in that project.

The way it works is when you call time() it calls _gettimeofday(). _gettimeofday() calls you time function (essentially a callback). You funtion uses some method to get the time and returns back up the stack.

======================================================

Hi everyone.

Thank you for all of your help. I would not have figured this out without you (or at least not without excesive cursing). I find it dissapointing that the 7U does not have an onboard clock, so that it would remember the time. :frowning:

And No, I don’t know how to set the localtime. If you have the code, that would be great.

Thanks,