Created
December 2, 2014 08:29
-
-
Save oz123/791ce3d53984ff6fcb0a to your computer and use it in GitHub Desktop.
A small reminder to self how to convert seconds since the epoch to GM time.
This file contains 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
#define _XOPEN_SOURCE | |
#include <string.h> | |
#include <time.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <locale.h> | |
// in main() | |
int | |
main(void) | |
{ | |
struct tm *tim; | |
setlocale(LC_ALL, ""); | |
char buf[255]; | |
time_t c; | |
c = strtoul("1412200800", NULL, 0); | |
tim = localtime(&c); | |
strftime(buf, sizeof(buf), "%c" , tim); | |
puts(buf); | |
printf("%s %s\n", tzname[0], tzname[1]); | |
tim = gmtime(&c); | |
strftime(buf, sizeof(buf), "%c" , tim); | |
puts(buf); | |
exit(EXIT_SUCCESS); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment