1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
//======================================================================
tm getTm()
{
time_t tt;
time( &tt );
return *localtime( &tt );
}
//======================================================================
void splitTm( const tm &TM, int &year, int &month, int &day, int &hour, int &mins, int &secs, int &weekDay )
{
year = TM.tm_year + 1900;
month = TM.tm_mon ;
day = TM.tm_mday;
hour = TM.tm_hour;
mins = TM.tm_min ;
secs = TM.tm_sec ;
weekDay = TM.tm_wday ;
}
//======================================================================
int main()
{
int year, month, day, hour, mins, secs, weekDay;
tm TM = getTm();
splitTm( TM, year, month, day, hour, mins, secs, weekDay );
cout << "Year = " << year << '\n';
string prefix = "xxx-";
string suffix = ".csv";
string filename = prefix + to_string( year ) + suffix;
cout << "Filename is " << filename << '\n';
}
//======================================================================
|
Year = 2017
Filename is xxx-2017.csv |