Today, I visited csdn and occasionally saw a post like a question. There are also a lot of people to follow, and various suggestions are put forward. I will also write my thoughts and ideas here. Hope that passers-by will show their mercy.
Ideas:
1. Obtain the day of the week. In the Time Structure struct TM in C ++, tm_wday indicates the day of the week, and 0 indicates Sunday. Here we need to change 0
7.
2. Obtain the date number. Tm_mday In the struct TM structure.
3. Set tm_mday/7 + (tm_mday % 7> tm_wday? 1-0) + 1, you can see the week of the current month.
# Include <iostream> <br/> # include <time. h> <br/> using namespace STD; <br/> int main () <br/>{< br/> TM * PTR; <br/> // <br/> time_t Ts = Time (null); <br/> PTR = localtime (& TS ); <br/> int week = PTR-> tm_wday; <br/> int day = PTR-> tm_mday; <br/> If (week = 0) Week = 7; <br/> cout <"today is" <asctime (PTR) <Endl; <br/> int th = day/7 + (day % 7> week? 1:0) + 1; <br/> cout <"Today is the" <th <"'s week of" <PTR-> tm_mon + 1 <Endl; <br/> return 0; <br/>}< br/>