1
ISO-8601의 시간을 십진 초의 정밀도로 인쇄하려고합니다. YYYY-MM ISO 형식 : mm : 나는 그것이 실행C : gettimeofday()는 매번 같은 값을 반환합니다.
#include <sys/time.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void milli_time(char* dest, struct timeval* t)
{
struct tm* timeInfo;
strftime(dest, 22, "%Y-%m-%dT%t", localtime(&t->tv_sec));
printf("%s\n", dest);
fflush(stdout);
char deciTime[3];
sprintf(deciTime, ".%lu", ((t->tv_usec)/100000ul));
strcat(dest, deciTime);
}
int main()
{
struct timeval* theTime;
char timeString[32];
gettimeofday(theTime, NULL);
printf("%lu.%lu\n", theTime->tv_sec, theTime->tv_usec);
milli_time(timeString, theTime);
printf("%s\n", timeString);
fflush(stdout);
}
그리고 출력 할 때마다 :
134520616.3077826840
1974-04-06T17:50:16
1974-04-06T17:50:16.30778
이 다른 것은 내가 알 여기
내 코드입니다 ss.s tv_usec이 백만 이상이라는 것입니다.
덕분에 많은 도움이되었습니다. – julianc