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:
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.
struct tm *local;
t = time(NULL);
local = localtime(&t);
fprintf(file_out, "Arrival time: %s\n", asctime(local) );
That's why i only need the time and not the dates etc....
Can anybody help me?
this is what u can do determine the time interval between two events.
(end-start)/CLOCKS_PER_SEC will give u the required time elapsed.
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.
You can also use difftime() to take the difference between to time_t values.