1

我有开始日期和月数。我需要创建特定数量的月度,例如:

var startingDate = new DateTime(2010,1,15);
var months = 3;
for (int i = 0; i < months; i++)
 {
 Console.WriteLine("{0} from {1} to {2}", i + 1, startingDate.AddMonths(i), 
startingDate.AddMonths(i + 1).AddDays(-1));
}
OUTPUT:
1 from 2010-1-15 to 2010-2-14
2 from 2010-2-15 to 2010-3-14
3 from 2010-3-15 to 2010-4-14

在这种情况下,代码很简单并且可以正常工作。然而,当 startDate 是 DateTime(2010,1,31) 结果是:

OUTPUT:
1 from 2010-1-31 to 2010-2-27
2 from 2010-2-28 to 2010-3-30
3 from 2010-3-31 to 2010-4-29

这些时期是否正确?

4

2 回答 2

1

这些时期确实看起来很时髦,但它们是正确的。

如果您的月经是从该月的最后一天开始的,那么它们将在下个月的倒数第二天结束。

于 2010-12-02T17:21:34.130 回答
1

你可以选择它们是对还是错。我的意思是:如果您在 1 月 15 日开始您的月经,您是在该月的第一天之后的 14 天开始,还是在最后一天的前 16 天开始?

它会变得更加棘手。如果 15 号是星期二,您的经期是否定义为从给定月份的第三个星期二开始?

There is a lot of literature about this in the financial community, since the Day Count Conventions, the Business Days, Rolling Conventions, etc. can make a lot of difference in the pricing of a financial product, and in the cash flows associated with it.

于 2010-12-02T18:40:18.400 回答