Skip to content

Instantly share code, notes, and snippets.

@dbussink
Created September 30, 2009 21:07
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 dbussink/198455 to your computer and use it in GitHub Desktop.
Save dbussink/198455 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <time.h>
int main(void)
{
time_t now;
struct tm *ts;
char buf[80];
/* Some distant moment in the past */
now = -10000000000;
/* Format and print the time, "ddd yyyy-mm-dd hh:mm:ss zzz" */
ts = localtime(&now);
strftime(buf, sizeof(buf), "%a %Y-%m-%d %H:%M:%S %Z", ts);
printf("%s\n", buf);
/* Try to get the timestamp moment back */
time_t now2 = mktime(ts);
printf("%i\n", now2);
return 0;
}
=============
Mon 1653-02-10 06:32:52 AMT
-1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment