※ 이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.
헤더파일 설명
- struct timeval은 bit/time.h 헤더파일에 정의 되어있다.
- bit/time.h 헤더파일은 sys/time.h 헤더파일에 선언되어 있다.
형식
strcut timeval
{
__time_t tv_sec; /* Seconds. */
__suseconds_t tv_usec; /* Microseconds. */
}
예제
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
int main(void){
struct timeval tv;
struct tm *ptm;
gettimeofday(&tv, NULL);
ptm = localtime(&tv.tv_sec);
printf("%d.%d\n", tv.tv_sec, tv.tv_usec);
printf("%d05d-%02d-%02d %d02d:%02d:%02d.%06ld\n"
, ptm->tm_year + 1900
, ptm->tm_mon + 1
, ptm->tm_mday
, ptm->tm_hour
, ptm->tm_min
, ptm->tm_sec
, tv.tv_usec);
return 0;
}
type 확인__time_t 타임은 8byte로 long 타입이다.
__suseconds 타입은 8byte로 long 타입이다.
#include <stdio.h>
#include <sys/time.h>
int main(void){
sturct timeval tv;
printf("%d\n", sizeof(tv.tv_sec));
printf("%d\n", sizeof(tv.tv_usec));
return 0;
}
'프로그래밍 언어' 카테고리의 다른 글
[DB] WITH 문 (가상 테이블) (0) | 2024.04.22 |
---|---|
[DB] ORACLE JOIN, ANSI JOIN (0) | 2024.04.22 |
[Java script] setInterval(), clearInterval() 응용 (0) | 2016.06.01 |
[Python] 이진파일과 텍스트파일 구분 (0) | 2014.10.05 |
[java script] window.open(url,name, opction) (0) | 2014.09.17 |