深入解析P89LPC930/931:双时钟内核、高集成度与低功耗设计实战
2026/6/11 12:51:13
time()函数返回自纪元(epoch)以来经过的秒数,以此表示当前时间。如果参数t不为NULL,该函数还会将当前时间写入该指针。出现错误时,函数返回 -1(转换为time_t类型),并适当地设置errno。唯一可能的错误是EFAULT,表示t是无效指针。
示例代码如下:
#include <stdio.h> #include <time.h> int main() { time_t t; printf ("current time: %ld\n", (long) time (&t)); printf ("the same value: %ld\n", (long) t); return 0; }gettimeofday()函数扩展了time()函数,提供了微秒级的分辨率。
#include <sys/time.h> int gettimeofday (struct timev