C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 04-30-2009, 08:26 PM   #1
Registered User
 
Join Date: May 2006
Posts: 19
How to get current time

Hello, i'm trying to print the current time but i'm getting it like this " Thu Apr 30 07:09:51 2009 "
I only need the time, i don't need the date, year etc...

How do i do that??

This is what i used:
Code:
    
time_t t;
    struct tm *local;
    t = time(NULL);
    local = localtime(&t);
...........
       fprintf(file_out, "Arrival time: %s\n", asctime(local)   );
...........
Right now i'm only trying to print the current time but what i really need is to be able to work with that time. Like i need to first use it as arrival time then use it to calculate how much time it takes to complete a certain job then finally i will have to print both on screen.

That's why i only need the time and not the dates etc....
Can anybody help me?
tsubasa is offline   Reply With Quote
Old 04-30-2009, 09:52 PM   #2
DESTINY
 
BEN10's Avatar
 
Join Date: Jul 2008
Location: in front of my computer
Posts: 656
this is what u can do determine the time interval between two events.
Code:
clock_t start,end;
start=clock();
//do something
end=clock();
(end-start)/CLOCKS_PER_SEC will give u the required time elapsed.
__________________
HOPE YOU UNDERSTAND.......

for( ; ; )
printf("If you can't make it good, at least make it look good");

PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
IDE- Microsoft Visual Studio 2008 Express Edition
BEN10 is offline   Reply With Quote
Old 04-30-2009, 10:04 PM   #3
Registered User
 
Join Date: Oct 2008
Location: TX
Posts: 1,262
How about printing out just those elements of the struct tm object you're interested in instead of the whole thing. Just my 2c, but in this case it maybe better to take the difference of the begin and end times (epoch) instead of first converting them to a human-readable form and then taking their difference as the job may rollover to next day and those difference calculations will then be incorrect.
itCbitC is offline   Reply With Quote
Old 05-01-2009, 02:03 AM   #4
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
You can also use difftime() to take the difference between to time_t values.

--
Mats
__________________
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
matsp is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Journey time prog 1 minute wrong mike_g C Programming 4 10-12-2006 03:41 AM
Military Time Functions BB18 C Programming 6 10-10-2004 01:57 PM
Killing someones grandparents nickname_changed A Brief History of Cprogramming.com 37 09-07-2003 07:56 AM
Is this really true or it's just science fiction? Nutshell A Brief History of Cprogramming.com 145 04-09-2002 06:17 PM
time class Unregistered C++ Programming 1 12-11-2001 10:12 PM


All times are GMT -6. The time now is 04:37 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22