Using ctime() to get the current time : Time « Development « C++






Using ctime() to get the current time

  
#include <time.h>
#include <iostream>
using namespace std;
int main()
{
   time_t currentTime;

   // get and print the current time
   time (&currentTime); // fill now with the current time
   cout << "It is now " << ctime(&currentTime) << endl;

   struct tm * ptm= localtime(&currentTime);

   cout << "Today is " << ((ptm->tm_mon)+1) << "/";
   cout << ptm->tm_mday << "/";
   cout << ptm->tm_year << endl;

   cout << "\nDone.";
   return 0;
}
  
    
  








Related examples in the same category

1.Use system timeUse system time
2.Overload date() for time_t.Overload date() for time_t.
3.Output a time value with ctime