Created
November 12, 2013 14:18
-
-
Save sschober/7431555 to your computer and use it in GitHub Desktop.
Extrahiert timestamp und localtime aus `UUID`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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