밀리초를 구현하는 방법
페이지 정보
본문
현재 시간을 읽어 화면에 표시하는 것을 하고 있는데, 연월일시분초 등을 나타내고 1000분의 1초(milliseconds) 단위도 표현하고 싶은데 어떻게 해야 하는지 방법을 알려주세요.
다음과 같이 하면 됩니다. 볼랜드 C++을 이용한다면 아래의 _timeb 구조체와 _ftime 함수 대신에 timeb 구조체와 ftime 함수를 사용해야 합니다. MS의 컴파일러(예를 들어 Visual C++) 에서는 아래의 코드대로 문제없이 돌아갈겁니다.
/* FTIME.C : This program uses _ftime to obtain the current
* time and then stores this time in timebuffer.
*/
#include <stdio.h>
#include <sys\timeb.h>
#include <time.h>
void main(void)
{
struct _timeb timebuffer;
char *timeline;
_ftime( &timebuffer );
timeline = ctime( &(timebuffer.time) );
printf("The time is %.19s.%hu %s", timeline, timebuffer.millitm,
&timeline[20] );
}
=== output ===
The time is Tue Mar 21 15:26:41.341 1995
다음과 같이 하면 됩니다. 볼랜드 C++을 이용한다면 아래의 _timeb 구조체와 _ftime 함수 대신에 timeb 구조체와 ftime 함수를 사용해야 합니다. MS의 컴파일러(예를 들어 Visual C++) 에서는 아래의 코드대로 문제없이 돌아갈겁니다.
/* FTIME.C : This program uses _ftime to obtain the current
* time and then stores this time in timebuffer.
*/
#include <stdio.h>
#include <sys\timeb.h>
#include <time.h>
void main(void)
{
struct _timeb timebuffer;
char *timeline;
_ftime( &timebuffer );
timeline = ctime( &(timebuffer.time) );
printf("The time is %.19s.%hu %s", timeline, timebuffer.millitm,
&timeline[20] );
}
=== output ===
The time is Tue Mar 21 15:26:41.341 1995
댓글목록
등록된 댓글이 없습니다.