Programing - C/C Basic grammar

126 날짜및 시간 구하기(localtime)

junmoyo 2018. 1. 9. 07:10

개념 : 


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;

}





결과: