溫馨提示×

linux c怎么獲取當前時間

小億
170
2024-08-12 07:55:32
欄目: 智能運維

在Linux系統中,可以使用time.h頭文件中的time()函數來獲取當前時間。以下是一個示例代碼:

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

int main() {
    time_t currentTime;
    time(&currentTime);

    printf("Current time: %s", ctime(&currentTime));

    return 0;
}

在上面的示例中,time()函數將當前時間的秒數存儲在currentTime變量中,然后使用ctime()函數將時間轉換為字符串并打印出來。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女