개념 :
1. 원형: struct tm* localtime(const time_t *time);
2. 파라메터 *time을 기준으로 struct tm* 으로 반환하여줍니다.
3. struct tm
#ifndef _TM_DEFINED
struct tm {
int tm_sec; /* seconds after the minute - [0,59] */
int tm_min; /* minutes after the hour - [0,59] */
int tm_hour; /* hours since midnight - [0,23] */
int tm_mday; /* day of the month - [1,31] */
int tm_mon; /* months since January - [0,11] */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday - [0,6] */
int tm_yday; /* days since January 1 - [0,365] */
int tm_isdst; /* daylight savings time flag */
};
#define _TM_DEFINED
소스코드 : main.c
#include<stdio.h>
#include<time.h>
int main(void)
{
time_t now;
struct tm t;
time(&now);
t = *localtime(&now);
printf("%d . %d . %d %d : %d : %d \n", t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
system("pause");
return 0;
}
결과:
'Programing - C > C Basic grammar ' 카테고리의 다른 글
128 날짜 및 시간을 문자열로 변환(ctime) (0) | 2018.02.18 |
---|---|
127 1/1000초 구하기 (_ftime) (0) | 2018.01.10 |
visual studio 에서 C4996 error 해결하기 (0) | 2018.01.09 |
125 시간 구하기 ( time ) (0) | 2018.01.05 |
124 현재 작업중인 드라이브 구하고 변경하기( _getdirve, _chdrive) (0) | 2018.01.04 |