set time value to a variable

1
2
3
4
5
6
7
8
9
10
11
12
#include "includes"

int main() {
	time_t rawtime;
	struct tm * timeinfo;
	char buffer [80];
	time ( &rawtime );
	timeinfo = localtime ( &rawtime );
	string timetest;
	timetest= strftime (buffer,80,"%Y-%m-%d",timeinfo);
    puts (buffer);
}


now instead of print the time i want add the value of the time to a variable
like this

Today=%d;
Month=%m;
Year=%y;

so i can use it where i want and when i want thnx.
i cant use it can you please give me an Exmaple Code thnx
Last edited on
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
#include <iostream>
#include <string>
#include <ctime>

using namespace std;

const string DAYS[]={"Sunday","Monday","Tuesday",
    "Wednesday","Thursday","Friday","Saturday"};

const string MONTHS[]={"January","February","March","April","May","June",
    "July","August","September","October","November","December"};

int main()
{
    int wday, mday, month, year;

    time_t rawtime;
    tm * timeinfo;

    time(&rawtime);
    timeinfo=localtime(&rawtime);

    wday=timeinfo->tm_wday;
    mday=timeinfo->tm_mday;
    month=timeinfo->tm_mon;
    year=timeinfo->tm_year;

    cout << DAYS[wday] << ", ";
    cout << MONTHS[month] << " " << mday << ", ";
    cout << 1900+year << endl;

    cout << "\nhit enter to quit...";
    cin.get();
    return 0;
}
Last edited on
1
2
3
4
5
6
7
int  year;
	time_t rawtime;
    tm * timeinfo;
    time(&rawtime);
    timeinfo=localtime(&rawtime);
	year=timeinfo->tm_year;
	cout << 1900+year;


the result always 0
NVM SOLVED IT
Topic archived. No new replies allowed.