초 단위로 시간을 가져온다.
#include <time.h> time_t time(time_t *t);
이 함수가 돌려주는 시간은 1970년 1월 1일 00:00:00 부터 지금까지의 시간을 초단위로 환산한것이다.
만약 아규먼트로 들어가는 t 가 NULL 이 아니라면 반환값은 t 가 가르키는 메모리에 저장된다.
성공하면 현재까지의 흐른시간을 초단위로 리턴한다. 에러가 발생할경우 -1 이 리턴된다.
t 가 가리키는 곳이 접근할수 없는 메모리 영역을 가르킬경우
#include <time.h> #include <stdio.h> #include <unistd.h> #include <sys/types.h> void swaptime(time_t, char *); int main() { int i; time_t the_time; char buffer[255]; // 현재 TIME 을 구한다. time(&the_time); printf("현재 시간은 %d 초\n", the_time); // 보기좋은 지역시간대로 바꾼다. swaptime(the_time, buffer); printf("%s\n", buffer); } void swaptime(time_t org_time, char *time_str) { struct tm *tm_ptr; tm_ptr = localtime(&org_time); sprintf(time_str, "%d/%d/%d %d:%d:%d", tm_ptr->tm_year+1900, tm_ptr->tm_mon+1, tm_ptr->tm_mday, tm_ptr->tm_hour, tm_ptr->tm_min, tm_ptr->tm_sec); }
[root@s210-205-210-195 test]# ./time 현재 시간은 1030294567 초 2002/8/26 1:56:7
Copyrights © - Joinc, All Rights Reserved. Inherited From - Yundream Rebranded By - Joonphil
1장. time(2)
초 단위로 시간을 가져온다.
1.1절. 사용법
1.2절. 설명
이 함수가 돌려주는 시간은 1970년 1월 1일 00:00:00 부터 지금까지의 시간을 초단위로 환산한것이다.
만약 아규먼트로 들어가는 t 가 NULL 이 아니라면 반환값은 t 가 가르키는 메모리에 저장된다.
1.3절. 반환값
성공하면 현재까지의 흐른시간을 초단위로 리턴한다. 에러가 발생할경우 -1 이 리턴된다.
1.4절. 에러
t 가 가리키는 곳이 접근할수 없는 메모리 영역을 가르킬경우
1.5절. 예제
Recent Posts
Archive Posts
Tags
About
Joinc proposes educational computer-engineering contents. Especially, the contents focus on recently popular and meaningful topics, technically helpful for those who already work or to-be developers in the computer industry and theoretical or typical topics covered in undergraduate courses.
Get in Touch
Categories
Subscribe
Subscribe to our mailing list to get the latest updates.
Copyrights © - Joinc, All Rights Reserved.
Inherited From - Yundream Rebranded By - Joonphil