Challenge solution with passed and present dates


#1

I decided to see what the date was 4 million seconds ago and what it will be in 4 million seconds time:

This is what I came up with (With a little help )

#include <stdio.h>
#include <time.h>
#include <stdlib.h>

int main(int argc, const char * argv[])

{

        //Seconds since 1970
    
    long secondsSince1970 = time(NULL);

    printf ( "Seconds passed since 1970: %ld\n", secondsSince1970);

        //Now
    struct tm now;

    localtime_r(&secondsSince1970, &now);

    printf( "Today is: %.2d-%.2d-%.4d\n", now.tm_mday, now.tm_mon + 1, now.tm_year + 1900);

        //Later
    
    long futureDate = secondsSince1970 + 4e6;
    
    struct tm later; 
    localtime_r(&futureDate, &later);

    printf ( "Date in 4 Million seconds: %.2d-%.2d-%.2d\n", later.tm_mday, later.tm_mon +1, later.tm_year + 1900);

        //Passed date (4 million seconds ago)

    long earlier = secondsSince1970 - 4e6;

    struct tm passedDate;

    localtime_r(&earlier, &passedDate);

    printf ( "The date was: %.2d-%.2d-%.2d, 4 million seconds ago\n", passedDate.tm_mday, passedDate.tm_mon + 1, passedDate.tm_year + 1900);


    EXIT_SUCCESS; 
}