Calculates the current calendar time.
Include
<time.h>
Prototype
time_t time(time_t * tod);
Argument
tod |
Return Value
Returns the calendar time encoded as a value of time_t
.
Remarks
If the target environment cannot determine the time, the function returns -1 cast as a
time_t
. By default, the compiler returns the time as instruction
cycles.
When using XC16, this function uses the device Timer2 and Timer3 to compute the current time.
Example
See the notes at the beginning of this chapter or section for
information on using printf()
or scanf()
(and other functions reading and writing the stdin
or
stdout
streams) in the example code.
#include <time.h>
#include <stdio.h>
volatile int i;
int main(void)
{
time_t ticks;
time(0); /* start time */
for (i = 0; i < 10; i++) /* waste time */
continue;
time(&ticks); /* get time */
printf("Time = %ld\n", ticks);
}
Example Output
Time = 256