Advertisement
s1ay3r44

Date.h Example

Nov 21st, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <time.h>
  2.  
  3. class Date{
  4. public:
  5.     Date();
  6.     Date(int);
  7.     ~Date();
  8.    
  9.     void setDate(int);
  10.  
  11.     int getDay(){ return day; }
  12.     int getMonth(){ return month; }
  13.     int getYear(){ return year; }
  14.  
  15.  
  16. private:
  17.     int day, month, year;
  18.  
  19. };
  20.  
  21. //Date.cpp
  22.  
  23. Date::Date(){
  24.     time_t now;
  25.     time(&now); // Sets now to current time
  26.     struct tm * timeinfo;
  27.     timeinfo = localtime(&now);
  28.    
  29.     day = timeinfo->tm_mday;
  30.     month = timeinfo->tm_mon;
  31.     year = timeinfo->tm_year;
  32. }
  33.  
  34. Date::Date(int dt){
  35.     time_t elapsedtime = dt;
  36.     struct tm * timeinfo;
  37.     timeinfo = localtime(& elapsedtime);
  38.  
  39.     day = timeinfo->tm_mday;
  40.     month = timeinfo->tm_mon;
  41.     year = timeinfo->tm_year;
  42. }
  43.  
  44. Date::~Date(){}
  45.  
  46. void Date::setDate(int dt){
  47.     time_t elapsedtime = dt;
  48.     struct tm * timeinfo;
  49.     timeinfo = localtime(& elapsedtime);
  50.  
  51.     day = timeinfo->tm_mday;
  52.     month = timeinfo->tm_mon;
  53.     year = timeinfo->tm_year;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement