C語言生成時間戳

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

void get_timestamp(char* timestamp)
{
	time_t seconds = time(NULL); //The function time(NULL) returns the time since the Epoch (00:00:00 UTC, January 1, 1970), measured in seconds.
	sprintf(timestamp, "%-llu", (unsigned long long int)seconds);
}

int main()
{
    char timestamp[12] = {};  // this array can record the second time by 2067
    get_timestamp(timestamp);
    printf("%s\n", timestamp);
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章