Skip to content

Instantly share code, notes, and snippets.

@josefsalyer
Forked from anonymous/whymathbad.c
Last active December 13, 2015 05:58
Show Gist options
  • Save josefsalyer/4877469 to your computer and use it in GitHub Desktop.
Save josefsalyer/4877469 to your computer and use it in GitHub Desktop.
//
// main.c
// ch10
//
// Created by john salyer on 2/12/13.
// Copyright (c) 2013 john salyer. All rights reserved.
//
#include <stdio.h>
#include <time.h>
int main(int argc, const char * argv[])
{
//what is now?
long secondsSince1970 = time(NULL);
struct tm now = *localtime(&secondsSince1970); //the number of seconds since jan 1 1970
//localtime_r(&secondsSince1970, &now);
printf("The date now is %d-%d-%d\n", now.tm_mon+1, now.tm_mday, now.tm_year+1900);
printf("days since Jan 1: %d \n",now.tm_yday+1);
//what is 4M seconds from now?
long fourmillion = 4000000;
long plusfourmillion = secondsSince1970 + fourmillion;
struct tm future;
localtime_r(&plusfourmillion, &future);
printf("The date in 4 million seconds will be %d-%d-%d\n", future.tm_mon+1, future.tm_mday, future.tm_year+1900);
//it should be something like 46.296296296 days!!!
printf("days since Jan 1: %d \n",future.tm_yday+1);
//why is it 47?
printf("What's %d - %d = %d\n",future.tm_yday+1, now.tm_yday+1, future.tm_yday - now.tm_yday );
//shouldn't be the number of seconds that we're calculating?
printf("Tell us the difference between NOW %li and THEN %li equals %li", secondsSince1970, plusfourmillion, secondsSince1970 - plusfourmillion);
return 0;
}
@josefsalyer
Copy link
Author

No.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment