preston Posted November 16, 2012 Share Posted November 16, 2012 Hi I'm wondering about the limitations of ctime and mktime. For example: time_t t; struct tm * timeinfo; string weekday[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; // get current timeinfo and modify it to user's choice t = time(NULL); timeinfo = localtime(&t); timeinfo->tm_year = local_year - 1900; timeinfo->tm_mon = local_month - 1; timeinfo->tm_mday = local_day; // call mktime: timeinfo->tm_wday will be set mktime(timeinfo); cout << "That day is a " << weekday[timeinfo->tm_wday] << endl; I am trying to determine the day of ANY date. Ideally, I would like it to be able to handle dates as far back as 5000 BC (if that is even possible) or year -5000....if not then maybe atleast 100 AD........ Am I asking C++ to do something it can't handle any more? How do I do what I described above in C++? What's the earliest date that ctime can handle? Is it only from 1970??? Thank you Link to comment Share on other sites More sharing options...
preston Posted November 16, 2012 Author Share Posted November 16, 2012 I just tested the above code...it only works properly from 1902 onwards... so now the question is... is there a convenient way for me to be able to determine the day of a particular date before 1902? or do I have to write that class myself? It's gonna be tricky...... Link to comment Share on other sites More sharing options...
Larry Posted November 16, 2012 Share Posted November 16, 2012 This is very tricky. You'll have to check online for the details, but around 1100, 10 days were added to the calendar and we switched from Julian to Gregorian calendars (or vice versa). And I don't know when leap days were introduced. It would kind of surprise me if there isn't a C++ library that handles this (to some degree) already. Link to comment Share on other sites More sharing options...
preston Posted November 19, 2012 Author Share Posted November 19, 2012 Hi Yes...I will check....for now I went with using NSDate and NSDateComponenets of Objective-C for the iOS version of the app....but with the Android version, I'll have to research more about other C++ libraries if I wanna reuse my C++ classes..... Thank you very much Link to comment Share on other sites More sharing options...
Kashif Posted January 7, 2015 Share Posted January 7, 2015 This is greatly average post........you shook posting it......thanks a lot.......!!! Link to comment Share on other sites More sharing options...
Recommended Posts