반응형
time(2)
#include <time.h>
time_t time(time_t *t);
time(2)함수는 1970-01-01 00:00:00 +0000 (UTC) 이후부터 현재까지 경과된 초단위 값을 return합니다. t가 NULL이 아니면 t에 결과값을 채우고 그 값을 return합니다. t가 NULL이면 경과된 초단위의 값만 return합니다.
파라미터
t
- 현재 시간을 저장할 데이터 buffer
- NULL이면 입력부는 무시됩니다.
RETURN
0 이상
- 1970-01-01 00:00:00 +0000 (UTC) 이후부터 현재까지의 경과 초
-1
- 오류가 발생하였으며, 상세한 오류는 errno에 저장됩니다.
EFAULT : t의 메모리 영역이 유효하지 않은 영역입니다.
활용 예제
Sample
#include <time.h>
#incldue <stdio.h>
int main(int argc, char **argv)
{
time_t t;
struct tm *lt;
if((t = time(NULL)) == -1) {
perror("time() call error");
return -1;
}
if((lt = localtime(&t)) == NULL) {
perror("localtime() call error");
return -1;
}
printf("지금시간: %04d-%02d-%02d %02d:%02d:%02d\n",
lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
lt->tm_hour, lt->tm_min, lt->tm_sec);
return 0;
}
see also : 시간 관련 함수
반응형
'C언어 header > time.h' 카테고리의 다른 글
ctime(3) - 초단위 시간을 문자열로 변환 (0) | 2019.09.30 |
---|---|
gmtime_r(3) - 초단위의 시간을 국제표준시(UTC) struct tm으로 변환(thread-safe) (0) | 2019.09.30 |
gmtime(3) - 초단위의 시간을 국제표준시(UTC) struct tm으로 변환 (0) | 2019.09.30 |
localtime_r(3) - 지역시간 struct tm 타입으로 변환(thread-safe) (0) | 2019.09.30 |
localtime(3) - 초단위 시간을 지역시간 struct tm 타입으로 변환 (0) | 2019.09.30 |