Get millisecond part of time

后端 未结 8 1956
再見小時候
再見小時候 2020-12-18 22:07

I need to get milliseconds from the timer

    // get timer part
    time_t timer = time(NULL);
    struct tm now = *localtime( &timer );
    char timesta         


        
8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-18 22:21

    Try with this code:

    struct tvTime;
    
    gettimeofday(&tvTime, NULL);
    
    int iTotal_seconds = tvTime.tv_sec;
    struct tm *ptm = localtime((const time_t *) & iTotal_seconds);
    
    int iHour = ptm->tm_hour;;
    int iMinute = ptm->tm_min;
    int iSecond = ptm->tm_sec;
    int iMilliSec = tvTime.tv_usec / 1000;
    int iMicroSec = tvTime.tv_usec;
    

提交回复
热议问题