在 C 语言中,你可以使用 time()
函数来获取当前时间戳。这个函数会返回从 1970 年 1 月 1 日至今的秒数。
你需要在代码中包含 time.h
头文件,然后就可以使用 time()
函数了。
例如:
#include <stdio.h>
#include <time.h>
int main() {
time_t t = time(NULL);
printf("当前时间戳: %ld\n", t);
return 0;
}
运行上面的代码会输出当前时间戳,例如:
当前时间戳:1609447813