日当周算法的一天? [英] Date to Day of the week algorithm?
本文介绍了日当周算法的一天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是算法,赋予了日,月,年,返回星期几?
What is the algorithm that, given a day, month and year, returns a day of the week?
推荐答案
这可以通过完成的<一个href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/mktime.html"><$c$c>std::mktime$c$c>和<一href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/localtime.html"><$c$c>std::localtime$c$c>功能。这些功能不仅仅是POSIX,它们是由C ++标准(C ++ 03§20.5)授权。
This can be done using the std::mktime
and std::localtime
functions. These functions are not just POSIX, they are mandated by the C++ Standard (C++03 §20.5).
#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';
这篇关于日当周算法的一天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文