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

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

vikrant321

Thread Starter
Joined
Aug 27, 2004
Messages
12
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.
 
Joined
Oct 12, 2003
Messages
3,015
Code:
#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 );
	
}
 
Joined
Apr 30, 2001
Messages
2,636
Here's the same thing, but just the time.

Code:
#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

Thread Starter
Joined
Aug 27, 2004
Messages
12
thanx for the solution , actually i had just got stuck when on a 'machine vision' project.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top