Home
 
 
Search:  
C C++ Perl PHP Python HTML ShellScripts
 
 
  Coding Books
  Tutorials
  Search Code
  Browse Code
  Link to Us
  Site News
  Contact Metalshell
 
 
 
  Submit Code   Statistics
 



Numerical Recipes in C : The Art of Scientific Computing    (ISBN: 0521431085)


 

 List Price: $70.00
 Our Price: $70.00
 Used Price: $35.00

 Release Date: January, 1993
 Manufacturer: Cambridge University Press (Hardcover)
 Sales Rank: 37,797

 Author: William H. Press, Brian P. Flannery, Saul A. Teukolsky, William T. Vetterling









More Info

 Time 2001-12-11 20:02:33
 
Category: source:c:math
Description: Prints formatted time to screen
Platform: unix/win
Author: detour
Viewed: 3535
Rating: 3.6/5 (15 votes)
If you have any questions about this piece of code or still need help, try posting your question on the forum.

 

Printable Version
time.c
/* time.c written by detour@metalshell.com
 *
 * prints current time to screen
 * prints formated time to screen
 *
 * http://www.metalshell.com/
 *
 */

#include <time.h>
#include <stdio.h>

void ftimestr(time_t);

int main() {
  time_t curtime;

  curtime=time(NULL);
  printf("Time: %s", asctime(localtime(&curtime)));
  ftimestr(curtime);
}

void ftimestr(time_t curtime) {
  char *ftime[30];

  strftime((char *) ftime, sizeof(ftime), 
        "Current Day: %A\nCurrent Year: %Y\nCurrent Month: %B\n",
        localtime(&curtime));

  printf("%s", ftime);
}

/*
 * Other options for strftime
 * 
 * %a abbreviated weekday name 
 * %A full weekday name 
 * %b abbreviated month name 
 * %B full month name 
 * %c appropriate date and time representation 
 * %d day of the month (01-31) 
 * %H hour of the day (00-23) 
 * %I hour of the day (01-12) 
 * %j day of the year (001-366) 
 * %m month of the year (01-12) 
 * %M minute of the hour (00-59) 
 * %p AM/PM designator 
 * %S second of the minute (00-61) 
 * %U week number of the year where Sunday is the first day of week 1 (00-53) 
 * %w weekday where Sunday is day 0 (0-6) 
 * %W week number of the year where Monday is the first day of week 1 (00-53) 
 * %x appropriate date representation 
 * %X appropriate time representation 
 * %y year without century (00-99) 
 * %Y year with century 
 * %Z time zone (possibly abbreviated) or no characters if time zone isunavailable 
 * %% % 
 */
Rate this code:
(Not Helpful)  (Very Helpful) 

 
 
   Developer.*  
   Blue Parrots  
   Technipal  
   Defy Magazine  
   Code Project  
   Prog. Heaven  


Got Money?