我怎样才能通过输入日期获得哪一天?
输入日期示例:15-08-2012
我怎么知道它的星期一,星期二或哪一天使用C++.
我试图从一个月的可用日期省略周末,所以如果我输入例如2012年8月,我想检查哪一天是星期六,哪一天是星期日,所以我可以从可用日期省略它对于我的节目.
我尝试获取一个月内的天数的代码:
if (month == 4 || month == 6 || month == 9 || month == 11)
{
maxDay = 30;
}
else if (month == 2)
//{
// bool isLeapYear = (year% 4 == 0 && year % 100 != 0) || (year % 400 == 0);
// if (isLeapYear)
// {
// maxDay = 29;
// }
//else
{
maxDay = 28;
}
Run Code Online (Sandbox Code Playgroud)
接下来我想知道的是那个月,哪一天是周末所以我可以从结果中省略.
#include <ctime>
std::tm time_in = { 0, 0, 0, // second, minute, hour
4, 9, 1984 - 1900 }; // 1-based day, 0-based month, year since 1900
std::time_t time_temp = std::mktime( & time_in );
// the return value from localtime is a static global - do not call
// this function from more than one thread!
std::tm const *time_out = std::localtime( & time_temp );
std::cout << "I was born on (Sunday = 0) D.O.W. " << time_out->tm_wday << '\n';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17509 次 |
| 最近记录: |