Time stamp in the C programming language

后端 未结 9 1419
别那么骄傲
别那么骄傲 2020-12-08 04:48

How do I stamp two times t1 and t2 and get the difference in milliseconds in C?

9条回答
  •  情歌与酒
    2020-12-08 05:47

    /*
     Returns the current time.
    */
    
    char *time_stamp(){
    
    char *timestamp = (char *)malloc(sizeof(char) * 16);
    time_t ltime;
    ltime=time(NULL);
    struct tm *tm;
    tm=localtime(<ime);
    
    sprintf(timestamp,"%04d%02d%02d%02d%02d%02d", tm->tm_year+1900, tm->tm_mon, 
        tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
    return timestamp;
    }
    
    
    int main(){
    
    printf(" Timestamp: %s\n",time_stamp());
    return 0;
    
    }
    

    Output: Timestamp: 20110912130940 // 2011 Sep 12 13:09:40

提交回复
热议问题