Skip to content

Instantly share code, notes, and snippets.

@omalley
Created April 7, 2015 19:11
Show Gist options
  • Select an option

  • Save omalley/f98dc64786933a53da22 to your computer and use it in GitHub Desktop.

Select an option

Save omalley/f98dc64786933a53da22 to your computer and use it in GitHub Desktop.

Revisions

  1. omalley created this gist Apr 7, 2015.
    27 changes: 27 additions & 0 deletions mac2038.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    #include <stdio.h>
    #include <time.h>

    /*
    Demonstrates the Mac OS bug for 2038. The output on Mac OS/X 10.10.2 in PDT:
    In 2036 2093587200 - 2093562000 = 25200
    In 2037 2125126800 - 2125101600 = 25200
    In 2038 2156666400 - 2156637600 = 28800
    In 2039 2188202400 - 2188173600 = 28800
    */

    int main(int argc, char *argv[]) {
    struct tm timeStruct;
    timeStruct.tm_sec = 0;
    timeStruct.tm_min = 0;
    timeStruct.tm_hour = 0;
    timeStruct.tm_mday = 5;
    timeStruct.tm_mon = 4;
    for(int year=2036; year < 2040; ++year) {
    timeStruct.tm_year = year - 1900;
    time_t local = mktime(&timeStruct);
    time_t utc = timegm(&timeStruct);
    printf("In %d %ld - %ld = %ld\n", year, local, utc, local - utc);
    }
    }