0
    time_t ltime;
    time( &ltime );
    tm *    pTm = localtime(&ltime);

    printf("%d",pTm->tm_wday);

output= 2 , how come while 2day is 8 -.- anyclue?

2 Answers 2

3

tm_wday is the weekday, indexed from 0 being Sunday, to 6 being Saturday.

It is 2 today because it's a Tuesday.

What you want to access for the day of the month is tm_mday.

See also:

Sign up to request clarification or add additional context in comments.

Comments

2

Because tm_wday is the day since Sunday. Therefore it is 2. What you want is tm_mday

http://www.cplusplus.com/reference/clibrary/ctime/tm/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.