C 언어

time

SpeeDr00t 2016. 8. 3. 13:07
반응형

time

1.소스

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

#define SIZE 256

int main( int argc , char ** argv )
{
    char buf[256];

    struct tm *loctime;
    time_t curtime = time(NULL);

    loctime = localtime(&curtime);

    fputs( asctime(loctime ) , stdout );


    strftime(buf, SIZE , "today is %A, %B %d \n", loctime );
    fputs( buf , stdout );

    strftime(buf, SIZE, "the time is %I:%M %p \n", loctime );
    fputs( buf , stdout);

return 0;
}


결과

hacker@ubuntu:~/c$ 
hacker@ubuntu:~/c$ 
hacker@ubuntu:~/c$ 
hacker@ubuntu:~/c$ gcc -o time1 time1.c 
hacker@ubuntu:~/c$ 
hacker@ubuntu:~/c$ ./time1 
Tue Aug  2 21:05:34 2016
today is Tuesday, August 02 
the time is 09:05 PM 
hacker@ubuntu:~/c$ 
hacker@ubuntu:~/c$ 
반응형