0

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.

2
Contributors
4
Replies
16
Views
4 Years
Discussion Span
Last Post by Suzie999
0

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;

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.