1. 程式人生 > >獲取系統時間顯示或存入陣列中

獲取系統時間顯示或存入陣列中

把時間存入陣列中 

#include<time.h>
#include <string.h>


int main()
{
	//獲取系統時間並把時間存到陣列中
	time_t  t;
	char  buf[128];
	memset(buf,0,sizeof(buf));
	struct tm *tmp;
	t = time(NULL);
	tmp = localtime(&t);
	strftime(buf,sizeof(buf),"%Y-%m-%d %H:%M:%S",tmp);
        
        return 0;
}

顯示時間

#include<time.h>
#include <string.h>
#include<stdio.h>

int main()
{
    time_t t;
    struct tm * st;
    time (&t);//獲取系統時間
    st = localtime (&t);
    printf ( "%d/%d/%d %d:%d:%d\n",st->tm_year+1900, st->tm_mon, st->tm_mday, st->tm_hour, st->tm_min, st->tm_sec);//輸出結果

    return 0;
}

連結動態庫 

 gcc main.c -I /new_lib/include -lsqlite3 -L /new_lib/lib        /new_lib/include  為庫所在位置

靜態庫

 arm-linux-gcc test.c -lfont -L.                  .  為當前路徑