Hi.
I'm having some touble printing year.

Here is the code where I expected an output of "Year: 2013"

time_t tm;
time(&tm);
struct tm ts;
errno_t err = localtime_s(&ts,&tm);
cout << "Year:\t" << ts.tm_year <<  endl;

But what I get is "Year: 113"

Appreciate any help offered.

You have to add 1900 to the year.

Blimey!, I'd have never gotten that, thanks.
Is it also standard to add 1 to tm_mon, as I have to to get correct month, but tm_mday seems fine?
cout << "Date:\t" << ts.tm_year + 1900 << ":" << ts.tm_mon + 1 << ":" << ts.tm_mday << endl;

Is it also standard to add 1 to tm_mon,

Yes. Both those are well documented "features" of time.h

Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.