BOJ 코딩테스트/Bronze
BOJ 10699번 : 오늘 날짜 (C++/Bronze 5)
dev스카이
2022. 8. 4. 15:23
10699번: 오늘 날짜
서울의 오늘 날짜를 출력하는 프로그램을 작성하시오.
www.acmicpc.net
문제
서울의 오늘 날짜를 출력하는 프로그램을 작성하시오.
출력
서울의 오늘 날짜를 "YYYY-MM-DD" 형식으로 출력한다.
예제 출력
2015-01-24
Solution
#include <iostream>
int main(){
std::cout << "2022-08-04";
return 0;
}
추가로, 문자열만 입력하는 것이 현재 날짜와 현재 시간을 출력할 수 있도록 하는 코드다.
#include <iostream>
#include <ctime>
#include <string>
#include <stdio.h>
const std::string currentDateTime() {
time_t now = time(0);
struct tm tstruct;
char buf[80];
tstruct = *localtime(&now);
strftime(buf, sizeof(buf), "%Y-%m-%d",&tstruct);
return buf;
}
int main() {
std::cout << currentDateTime();
}