linux c++获取年月日
#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;
}
浙公网安备 33010602011771号