#include <stdio.h> #include <string.h> #include <string> #include <iostream> using namespace std; #define CHAR char int GetDate(const string &fmt, string &result) { CHAR buf[256]; time_t currtime; time(&currtime); struct tm *today = localtime(&currtime); if(strftime(buf, 256, fmt.c_str(), today)>0) { result = string(buf); return result.size(); } return -1; } int main() { string Val; GetDate("%Y-%m-%d",Val);; cout<<Val<<endl; return 0; }
原文:https://www.cnblogs.com/hshy/p/14399751.html