The current week is the week of this month.

Source: Internet
Author: User

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/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.