thedarkness

Gonna put this in here because there is no C++ code repository (perk?  Applause ).

Just wrote this. It's trivial but it may help someone and I was interested in the use of iomanip which, surprisingly, I haven't realy delved into before.

This prints yesterday's (now - 86400 seconds) date, formatted as I wanted it, could easily be modified to perform a lot of date related tasks........

#include <time.h>
#include <iostream>
#include <iomanip> // For formatting output

using namespace std;

int main( void )
{
  time_t now;
  struct tm * timeinfo;
  time( &now );
  now -= 86400; // Seconds in a day
  timeinfo = localtime( &now );

  cout << setfill('0' ) << setw( 2 ) << timeinfo->tm_mday << " "
       <<  setw( 2 ) << timeinfo->tm_mon + 1 << " " << setw( 2 )
       << timeinfo->tm_year - 100 << endl;
}


Cheers,
td

perkiset

I just put one in and am delighted TD - didn't think anyone would still be using those <>dinosaurs languages anymore such that we'd need one

:grabs helmet, dives into foxhole:

Please post this there - nice one!

/p

thedarkness

Applause


Perkiset's Place Home   Politics @ Perkiset's