// L-4 MCS 360 Mon 30 Aug 2010 : current_time.cpp

/* Calling time with 0 returns the date and time in seconds.

   Applying asctime on this value returns the string we see
   when we type date at the command prompt on a Unix(-like) OS.
   The function gmtime (Greenwich Mean time) breaks this number 
   returned by time into a structure with useful values.
   To see the local time, we call localtime. 

The purpose of this program is to provide a motivation for
a class to encapsulate technical C code.

We also demonstrate to set the width of fields of the output
via the i/o manipulators. */

#include<ctime>
#include<iostream>
#include<iomanip>

using namespace std;

int main()
{
   long int now = time(0); // current time

   string s = asctime(localtime(&now));
   cout << s;

   struct tm *tm_ptr;
   // tm_ptr = gmtime(&now); // Greenwich Mean time
   tm_ptr = localtime(&now);

   cout << "the raw time is " << now << endl;

   cout << setfill('0');

   cout << "The current date is "
        << 1900 + tm_ptr -> tm_year << "/"
        << setw(2) << 1 + tm_ptr -> tm_mon << "/"
        << setw(2) << tm_ptr -> tm_mday << "." << endl;

   cout << "The current time is "
        << setw(2) << tm_ptr -> tm_hour << ":"
        << setw(2) << tm_ptr -> tm_min << ":"
        << setw(2) << tm_ptr -> tm_sec << "." << endl;
  
   return 0;
}

