The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 20, 2019, 11:29:40 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: time/date manipulation  (Read 2834 times)
thedarkness
Lifer
*****
Offline Offline

Posts: 585



View Profile
« on: April 21, 2007, 02:16:49 AM »

Gonna put this in here because there is no C++ code repository (perk?  Don't make me... ).

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........

Code:
#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
« Last Edit: April 21, 2007, 05:21:12 AM by thedarkness » Logged

"I want to be the guy my dog thinks I am."
 - Unknown
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #1 on: April 21, 2007, 11:29:43 AM »

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
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
thedarkness
Lifer
*****
Offline Offline

Posts: 585



View Profile
« Reply #2 on: April 21, 2007, 04:07:31 PM »

 ROFLMAO
Logged

"I want to be the guy my dog thinks I am."
 - Unknown
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!