-
C++연습_날짜와 시간을 문자열로 변환하기(localtime)코딩Coding/C++_연습 2020. 9. 18. 00:02728x90
VSCode Cmake로 실행함.
#include <iostream> #include <string> #include <ctime> const std::string currentDataTime() { time_t now = time(0); struct tm tstruct; char buf[80]; tstruct = *localtime(&now); strftime(buf, sizeof(buf), "%Y-%m-%d.%X", &tstruct); return buf; } int main() { std::cout << "currenDateTime()=" << currentDataTime() << std::endl; getchar(); }
결과
stackoverflow.com/questions/997946/how-to-get-current-time-and-date-in-c
반응형'코딩Coding > C++_연습' 카테고리의 다른 글
C++연습_반복되는 문자 숫자 세기_입력하는거로 수정해야함 (0) 2020.11.28 C++연습_문자열 연결 (0) 2020.11.26 C++연습_Hello, World 출력하기 (0) 2020.10.17 C++연습_프로그램 실행 폴더 알아내기 (0) 2020.09.22 C++연습_전역변수(Global variable) (0) 2020.09.20 C++연습_문자열 비교하기(string.compare) (0) 2020.09.18 C++연습_난수 생성하기(Random number) (0) 2020.09.17 C++연습_Hello World출력 (0) 2020.09.02