samedi 1 mai 2021

How to compare date and time given in string format in c++? preferably using library?

I wonder to know how i can compare date and time in a string format in C++? In other words my question is that how can i implement the compare function for the following class using libraries?

class DateTime {
  private: 
   string date =;
   string time ;
  public :
     DateTime (string d, string t) :date (d), time(t) {
     }
     DateTime diff (DateTime t1, DateTime t2) {
     //?
     }
};

let's assume i call it as below

DateTime from ("2020-11-09", "06:22:30");
DateTime to ("2021-04-03", "23:54:13");
Date diff = to.diff (from ,to);

This is just an example, any suggestion for comparing a date and time is appreciated. The constraint i have is that date and time are given in string format, it would be great if i can return their differences in second or in similar string format shown above.

i have tried this struct in VScode, but i get the compilation error that it cannot recognize the time_t variable members.

Aucun commentaire:

Enregistrer un commentaire