home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C Programming Starter Kit 2.0
/
SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso
/
tyc
/
list19_2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-16
|
1KB
|
60 lines
/* Demonstrates the time functions. */
#include <stdio.h>
#include <time.h>
main()
{
time_t start, finish, now;
struct tm *ptr;
char *c, buf1[80];
double duration;
/* Record the time the program starts execution. */
start = time(0);
/* Record the current time, using the alternate method of */
/* calling time(). */
time(&now);
/* Convert the time_t value into a type tm structure. */
ptr = localtime(&now);
/* Create and display a formatted string containing */
/* the current time. */
c = asctime(ptr);
puts(c);
getch();
/* Now use the strftime() function to create several different */
/* formatted versions of the time. */
strftime(buf1, 80, "This is week %U of the year %Y", ptr);
puts(buf1);
getch();
strftime(buf1, 80, "Today is %A, %x", ptr);
puts(buf1);
getch();
strftime(buf1, 80, "It is %M minutes past hour %I.", ptr);
puts(buf1);
getch();
/* Now get the current time and calculate program duration. */
finish = time(0);
duration = difftime(finish, start);
printf("\nProgram execution time = %f seconds.", duration);
/* Also display program duration in hundredths of seconds */
/* using clock(). */
printf("\nProgram execution time = %ld hundredths of sec.",
clock());
}