Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. string DateTime::getFuture(unsigned int N)
  2. {
  3.     string future;
  4.     int days = date.tm_mday + N;
  5.     int mon = date.tm_mon;
  6.     int year = date.tm_year;
  7.     while (days > daysInMonth[mon])
  8.     {
  9.         days -= daysInMonth[mon];
  10.         mon++;
  11.         if (mon == 11)
  12.         {
  13.             mon = 0;
  14.             year++;
  15.         }
  16.     }
  17.     time_t seconds = time(NULL);
  18.     tm newdate = *localtime(&seconds);
  19.     newdate.tm_mday = days;
  20.     newdate.tm_mon = mon;
  21.     newdate.tm_year = year;
  22.     mktime(&newdate);
  23.     if (days < 10)
  24.     {
  25.         future = "0";
  26.     }
  27.     future += to_string(newdate.tm_mday) + " "
  28.         + months[newdate.tm_mon] + " "
  29.         + to_string(newdate.tm_year + 1900) + ", "
  30.         + week[newdate.tm_wday];
  31.     return future;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement