从日数计算日期? [英] Calculating the date from day-number?
本文介绍了从日数计算日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从C ++中的日数计算日期?我不需要你写整个代码,我只是不能弄清楚数学来计算月份和日期!
How would one go about calculating a date from a day-number in C++? I don't require you to write the whole code, I just can't figure out the maths to calculate the month and the day-of-month!
示例:
input: 1
output: 01/01/2012
input: 10
output: 01/10/2012
input: 365
output: 12/31/2012
它总是使用当前年份,如果他们超过365,我会返回0.没有必要闰年检测。
It would always use the current year, if they exceeded 365, I would return 0. There is no need for a leap-year detection.
推荐答案
使用日期calc库如eg精致的 Boost Date_Time 图书库,它将成为
Use a date calc library as e.g. the fine Boost Date_Time library with which this becomes
using namespace boost::gregorian;
date d(2012,Jan,1); // or one of the other constructors
date d2 = d + days(365); // or your other offsets
这篇关于从日数计算日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文