# C/C++ ,sample code to get current time of the system



## vikrant321 (Aug 27, 2004)

can any body reply with the module for retriving current system time in C/C++. i tried with "sys/timeb.h" and "ftime " function but , could not get.


----------



## coderitr (Oct 12, 2003)

```
#include "time.h"

int main( int argc, char *argv[] )
{
	time_t tm;
	struct tm *ltime;
	
	time( &tm );
	
	ltime = localtime( &tm );
	ltime->tm_mon++;
	ltime->tm_year += 1900;
	
	printf( "%02i.%02i.%04i  %02i:%02i:%02i\n\0", ltime->tm_mon,
		ltime->tm_mday, ltime->tm_year, ltime->tm_hour, ltime->tm_min, ltime->tm_sec );
		
	return( 0 );
	
}
```


----------



## Shadow2531 (Apr 30, 2001)

Here's the same thing, but just the time.


```
#include <iostream>
#include <ctime>

using namespace std;

int main() {
   const time_t curr = time(NULL);
   const tm* local = localtime(&curr);
   cout << endl << local->tm_hour << "h:" << local->tm_min << "m:" 
        << local->tm_sec << "s" << endl;
}
```


----------



## vikrant321 (Aug 27, 2004)

thanx for the solution , actually i had just got stuck when on a 'machine vision' project.


----------

