😸
[C] time 関数
機能
日付や時刻の情報を取得・操作する標準ライブラリ。[1]
使用例
現在のUNIX時刻を表示する
と表示する
\n
は改行を表す エスケープシーケンス[2]
コード
time_t t = time(NULL);
printf("%ld\n", t);
全文
#include <stdio.h>
#include <time.h>
void main() {
time_t t = time(NULL);
printf("%ld\n", t);
}
実行結果
1720451210
現在の日時を文字列で表示する
を変数から表示する
コード
time_t t = time(NULL);
char *s = ctime(&t);
printf("%s", s);
全文
#include <stdio.h>
#include <time.h>
void main() {
time_t t = time(NULL);
char *s = ctime(&t);
printf("%s", s);
}
実行結果
Tue Jun 4 12:46:50 2024
Discussion