home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / c / cuj9301.zip / 1101116A < prev    next >
Text File  |  1992-11-19  |  985b  |  45 lines

  1. /* time1.c: Various formats of date and time */
  2.  
  3. #include <stdio.h>
  4. #include <time.h>
  5.  
  6. #define BUFSIZE 128
  7.  
  8. main()
  9. {
  10.     time_t tval;
  11.     struct tm *now;
  12.     char buf[BUFSIZE];
  13.     char *fancy_format =
  14.       "Or getting really fancy:\n"
  15.       "%A, %B %d, day %j of %Y.\n"
  16.       "The time is %I:%M %p.";
  17.  
  18.     /* Get current date and time */
  19.     tval = time(NULL);
  20.     now = localtime(&tval);
  21.     printf("The current date and time:\n"
  22.            "%d/%02d/%02d %d:%02d:%02d\n\n",
  23.       now->tm_mon+1, now->tm_mday, now->tm_year,
  24.       now->tm_hour, now->tm_min, now->tm_sec);
  25.     printf("Or in default system format:\n%s\n",
  26.       ctime(&tval));
  27.     strftime(buf,sizeof buf,fancy_format,now);
  28.     puts(buf);
  29.  
  30.     return 0;
  31. }
  32.  
  33. /*  Output
  34. The current date and time:
  35. 10/06/92 12:58:00
  36.  
  37. Or in default system format:
  38. Tue Oct 06 12:58:00 1992
  39.  
  40. Or getting really fancy:
  41. Tuesday, October 06, day 280 of 1992.
  42. The time is 12:58 PM.
  43. */
  44. /* End of File */
  45.