Advertisement
congdantoancau

C++ Get current date and time

Dec 17th, 2017
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include <time.h>
  2. time_t theTime = time(NULL);
  3. struct tm *aTime = localtime(&theTime);
  4.  
  5. int day = aTime->tm_mday;
  6. int month = aTime->tm_mon + 1; // Month is 0 – 11, add 1 to get a jan-dec 1-12 concept
  7. int year = aTime->tm_year + 1900; // Year is # years since 1900
  8. int hour=aTime->tm_hour;
  9. int min=aTime->tm_min;
  10.  
  11. // Source: http://www.cceye.com/c-get-current-hour-minutes-of-the-day/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement