



(15 votes)/* 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 * %% % */