点击(此处)折叠或打开
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #include <sys/time.h>
- #include <unistd.h>
- char *get_time_for_uuid(char *time_string)
- {
- time_t timep;
- struct tm *p;
- struct timeval tv;
- int msec = 0;
- gettimeofday (&tv , NULL);
- time(&timep);
- p=gmtime(取地址符号timep);
- msec = tv.tv_usec/1000;
- sprintf(time_string, "百分号.4d%.2d%.2d%.2d%.2d%.2d%.2d",
- (1900+p->tm_year),
- (1+p->tm_mon),
- p->tm_mday,
- p->tm_hour,
- p->tm_min,
- p->tm_sec,
- msec
- );
- fprintf(stdout, "T-bagwell |%s|\n", time_string);
- return time_string;
- }
- int main()
- {
- char *uuid = NULL;
- char time_string[32];
- memset(time_string, 0, 32);
- uuid = get_time_for_uuid(time_string);
- fprintf(stdout, "T-bagwell the uuid = |%s|\n", uuid);
- return 0;
- }