I need someone to direct me to a simple but thorough explanation of the time funtions cos I can;t make head nor tail off them.
I want to print the time now and be able to calculate time difference.
Thanx
I need someone to direct me to a simple but thorough explanation of the time funtions cos I can;t make head nor tail off them.
I want to print the time now and be able to calculate time difference.
Thanx
time_t time() will give you time passed since epoch which is 00:00:00 January 1 1970. To find out difference between two times, you need to create the time_t entries for both times and subtract the two. This will give you number of seconds difference between the two times.
use mktime to get seconds from epoch for a given time. The parameters to mktime are a structure pointer to tm
tm takes the following values -->
1) tm_sec --> seconds in your time
2) tm_min
3) tm_hour
4) tm_mday --> day of month
5) tm_mon --> month
6) tm_year --> no of years since 1900
The rest of the info you can ignore.
subtract the two time_t values will get you the difference.
My best code is written with the delete key.
Code:#include <stdio.h> #include <stdlib.h> #include <time.h> char *get_system_time_(); int main() { printf("%s", get_system_time_()); system("pause"); return 0; } char *get_system_time_() { time_t now; time(&now); return asctime(localtime(&now)); }
Look in time.h to see all of the different functions that can be used, and the member data of struct tm.