Recommanded Free YOUTUBE Lecture: <% selectedImage[1] %>
  1. microtime
  2. unixtimestamp 형태의 시간과 초단위 미만의 시간을 구한다.
  3. acidd15
  4. Version 0.1
  5. 2004/04/02

설명

unixtimestamp 형태의 시간과 초단위 미만의 시간을 구한다.

사용방법

아래 코드를 참조하기 바란다.

코드

#include <stdio.h>
#include <malloc.h>
#include <sys/time.h>

int microtime(long *,double *);

int main(int argc,char **argv){

    long sec;
    double msec;
    char ret[100];

    microtime(&sec,&msec);

    snprintf(ret,100,"%.8f %1d",msec,sec);

    printf("%s\n",ret);
    return 0;

}

int microtime(long *sec,double *msec){

    struct timeval tp;

    if(gettimeofday((struct timeval *)&tp,NULL)==0){

        (*msec)=(double)(tp.tv_usec/1000000.00);
        (*sec)=tp.tv_sec;

        if((*msec)>=1.0) (*msec)-=(long)(*msec);

        return 0;

    }else{

        return 1;

    }

}

변경사항

2004/01/08