Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get system time and date cpp
03-11-2010, 04:38 AM
Post: #1
Get system time and date cpp
You can extract system time and date with localtime() function.
There are ways to do it using time() function from <time.h>, but this is easier.
This works with time_t type and here is the code that you can use :
Code:
# include <iostream>
# include <cstdio>
# include <time.h>

using namespace std;

int main ()
{
  time_t rawtime;
  struct tm * timeinfo;
  time ( &rawtime );
  timeinfo = localtime ( &rawtime );
  cout<<"Current local time and date: "<<asctime(timeinfo)<<endl;
  system("pause");
}
This would output :
Code:
Current local time and date: Wed Mar 10 19:30:00 2010
You can easily manipulate with output, and you don+t have to use struct for timeinfo.

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
03-11-2010, 05:42 AM
Post: #2
RE: Get system time and date cpp
Nice. Thanks for sharing.
Find all posts by this user
Quote this message in a reply
12-31-2010, 06:08 AM
Post: #3
RE: Get system time and date cpp
Very nice.

Are there any functions for manipulating time intervals?
Find all posts by this user
Quote this message in a reply
12-31-2010, 06:49 AM
Post: #4
RE: Get system time and date cpp
Nice Smile I need things like this, cos I am kinda starter in C++ Smile

Read rules Smile
[Image: legislator.png]
Find all posts by this user
Quote this message in a reply
12-31-2010, 07:46 AM
Post: #5
RE: Get system time and date cpp
(12-31-2010 06:08 AM)TheBear Wrote:  Very nice.

Are there any functions for manipulating time intervals?
If you mean like delay or sleep functions, yeah, we have one for C/C++ here :
http://www.pro9ramming.com/sleep-functio...t-965.html

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: