使用当前系统日期C ++将当前月打印为日历

时间:2015-06-15 22:06:37

标签: c++ calendar timestamp

第一次发布海报,如果我犯了任何错误,请原谅我。

我对C ++中的整个编程相当新,但我想知道是否可以打印出某个月的日历(当前日历),例如今天是2015年6月所以我想用C ++打印出2015年6月的月历

如果有人有任何建议如何使这成为可能,那将是非常有帮助的。我知道如何使用用户输入发布当前月份,但我希望我的程序查看系统日期。

提前致谢。

1 个答案:

答案 0 :(得分:0)

使用时间(0)得到time_t,也就是自xxxoopsxxxxx =>以来的某个秒数。时代:1969年12月31日星期三19:00:00,1970年1月1日

time_t linearTime = time(0);

使用localtime_r将linearTime转换为

struct tm timeinfo = *localtime_r(&linearTime, &timeinfo);

使用struct tm解码细分时间(在Linux中,在/usr/include/time.h)并根据需要生成日历。

玩得开心。

编辑2

看着时间。弄清楚如何衡量我们的持续时间。

但是,下面的计时内容与之前的东西非常相似。

std::time_t t0 = std::time(nullptr);
std::tm* localtime(const std::time_t* t0); // std::tm has the fields you expect

// convenient to text
std::cout << std::asctime(std::localtime(&t0)); // prints the calendar info for 'now'

我怀疑没有太大的不同。

编辑3

我有疑问。我认为以前可疑的比特来自ctime,而不是时间。所以我计划在计时中挖掘更多。

相关问题