1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

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

Discussion in 'Software Development' started by vikrant321, Sep 4, 2004.

Thread Status:
Not open for further replies.
Advertisement
  1. vikrant321

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

    coderitr

    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 );
    	
    }
     
  3. Shadow2531

    Shadow2531

    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;
    }
    
     
  4. vikrant321

    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.
     
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 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/270025

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice