Skip to content

Instantly share code, notes, and snippets.

@oz123
Created December 2, 2014 08:29
Show Gist options
  • Save oz123/791ce3d53984ff6fcb0a to your computer and use it in GitHub Desktop.
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.
#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