There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Software Development
Tag Cloud
audio blue screen boot bsod computer cpu crash dell desktop driver drivers error excel external hard drive firefox freezes freezing hard drive hardware hijackthis internet internet explorer itunes laptop malware monitor motherboard mouse network networking outlook 2007 power printer problem ram router screen slow sound spyware trojan usb virus vista vista 32-bit windows windows xp windowsxp winxp wireless
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
C/C++ ,sample code to get current time of the system


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

Closed Thread
 
Thread Tools
vikrant321's Avatar
Junior Member with 12 posts.
 
Join Date: Aug 2004
Experience: Intermediate
04-Sep-2004, 08:39 AM #1
Question C/C++ ,sample code to get current time of the system
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's Avatar
Distinguished Member with 3,080 posts.
 
Join Date: Oct 2003
04-Sep-2004, 07:39 PM #2
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 );
	
}
Shadow2531's Avatar
Distinguished Member with 2,629 posts.
 
Join Date: Apr 2001
05-Sep-2004, 01:42 AM #3
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's Avatar
Junior Member with 12 posts.
 
Join Date: Aug 2004
Experience: Intermediate
06-Sep-2004, 03:14 AM #4
Smile thanx coderitr and shadow2531, thanx both of u !
thanx for the solution , actually i had just got stuck when on a 'machine vision' project.

Last edited by vikrant321 : 06-Sep-2004 04:37 AM.
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 10:04 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.