Skip to content

Instantly share code, notes, and snippets.

@sschober
Created November 12, 2013 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sschober/7431555 to your computer and use it in GitHub Desktop.
Save sschober/7431555 to your computer and use it in GitHub Desktop.
Extrahiert timestamp und localtime aus `UUID`
#include <uuid.h>
#include <stdio.h>
#include <time.h>
int main(int argc, char** argv){
if(argc<2) return 1;
uuid_t uuid;
if( uuid_parse(argv[1],uuid) < 0 ){
return 1;
}
time_t time;
struct timeval ret_tv;
time = uuid_time(uuid, &ret_tv);
printf("timestamp: %ld\n", time);
struct tm *tm;
char fmt[64], buf[64];
if((tm = localtime(&ret_tv.tv_sec)) != NULL){
strftime(fmt, sizeof fmt, "%Y-%m-%d %H:%M:%S.%%06u %z", tm);
snprintf(buf, sizeof buf, fmt, ret_tv.tv_usec);
printf("localtime: %s\n", buf);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment