Home Segments Index Top Previous Next

715: Mainline

Other examples are shown on the next page.

#include   
#include  
time_t elapsed_seconds; 
struct tm *time_structure_pointer; 
char time_buffer[100]; 
main ( ) { 
  time(&elapsed_seconds); 
  time_structure_pointer = localtime (&elapsed_seconds); 
  /* Line 1 */ 
  strftime (time_buffer, 100, "%I:%M %p", time_structure_pointer); 
  printf ("The civilian time is %s.\n", time_buffer); 
  /* Line 2 */ 
  strftime (time_buffer, 100, "%H:%M", time_structure_pointer); 
  printf ("The military time is %s.\n", time_buffer); 
  /* Line 3 */ 
  strftime (time_buffer, 100, "%d %B %Y", time_structure_pointer); 
  printf ("One way to write the date is %s.\n", time_buffer); 
  /* Line 4 */ 
  strftime (time_buffer, 100, "%m/%d/%y", time_structure_pointer); 
  printf ("A shorter way to write the date is %s.\n", time_buffer); 
} 
--- Result --- 
The civilian time is 01:41 PM. 
The military time is 13:41. 
One way to write the date is 22 April 1994. 
A shorter way to write the date is 04/22/94.