Hello All, I currently have a small problem. In my game, I have need of being able to record the current time, to save as a string (will save string to json using my own means), and then reload said string and compare to current time. My goal is to end with a value with the number of days since the last time was written to the file. Aka, it can be (10.6 days) or something. I just need a way of recording time to string, and comparing the times. I have tried using diff-time, but to no avail. Here is something I have tried.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <ctime>
#include <iostream>
usingnamespace std;
int main() {
time_t t = time(0); // get time now
struct tm * now = localtime(&t);
cout << (now->tm_year + 1900) << '-'
<< (now->tm_mon + 1) << '-'
<< now->tm_mday
<< endl;
time_t old = time(0);
struct time * now = localtime(&old);
cout << (now->time_year + 1900);
}