Linux/C/獲取系統當前時間

c語言獲取系統當前時間,本想獲取毫秒的,沒找到方法,直接用微妙了。

獲取的時間爲自 Unix 紀元起至當前的秒數/微數。


#include <sys/time.h>
#include <stdio.h>

int main()
{
	struct timeval t;
	gettimeofday(&t,NULL);
	printf("---------------------------->time:%d\n",t.tv_sec);  //秒
	printf("---------------------------->time:%d\n",t.tv_usec); //微秒(1/1000000秒)
}




發佈了23 篇原創文章 · 獲贊 35 · 訪問量 16萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章