Created
April 18, 2013 17:48
-
-
Save sbp/5414770 to your computer and use it in GitHub Desktop.
Print a unixtime
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 <math.h> | |
#include <stdio.h> | |
#include <time.h> | |
int main() { | |
double time; | |
struct tm *gm_t; | |
size_t size; | |
char s[128]; | |
time = 1366303735.958; | |
int unixtime = (int)floor(time); | |
// http://stackoverflow.com/questions/5589383 | |
// Extract fractional part of double *efficiently* in C | |
double fraction = time - ((long)time); // or int64_t | |
gm_t = gmtime((time_t *)&unixtime); | |
size = strftime(s, sizeof(s), "%a, %d %b %Y %T.%%s %z\n", gm_t); | |
char *fr[8]; | |
s[size] = 0; | |
sprintf(fr, "%f", fraction); | |
// printf("%s", (char *)&fr + 2); | |
printf(s, (char *)&fr + 2); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment