c++ time.h 헤더

4690 단어 time_ttmCC

strftime >> time을 str으로 바꿔줌

size_t strftime(char *s, size_t maxsize, const char *format,
                   const struct tm *timeptr);
struct tm
{
int tm_sec; // seconds after the minute - [0, 60] including leap second
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
};

사용법

#include <time.h>
#include <iostream.h>

int main()
{
    time_t now;
    struct tm *time_info;
    char	buffer[20];
    
    time(&now); // 현재 시간을 now에 저장
    time_info = localtime(&now); // now의 시간 정보를 tm구조체에 저장
    strftime(buffer, 20, "[%Y%m%d_%H%M%S]", time_info); // 시간정보를 buffer에 str형태로 저장
    std::cout << buffer; // 출력
}

좋은 웹페이지 즐겨찾기