如何获取每月周期列表?

发布于 2024-10-05 20:58:21 字数 594 浏览 0 评论 0原文

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

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

这些时间段正确吗?

I have starting date and number of months. I need to create specific number of monthly periods for example:

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

In this case code is simple and it works.
However when startDate is DateTime(2010,1,31) result is:

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

Are these periods correct?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眸中客 2024-10-12 20:58:21

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

如果您的经期从该月的最后一天开始,则将在下个月的倒数第二天结束。

The periods do look funky but they are correct.

If your periods are starting on the last day of the month they will end on the second to last day of the next month.

鸠书 2024-10-12 20:58:21

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

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

金融界有很多关于这方面的文献,因为日计数惯例、营业日、滚动惯例等可以对金融产品的定价以及与之相关的现金流产生很大的影响。

You get to choose if they are right or wrong. Here is what I mean :
If you start your period on the 15th of January, are you starting 14 days after the first day of the month, or are you starting 16 days before the last?

It can get even more tricky. If the 15th is a Tuesday, is your period defined as starting the 3rd Tuesday of a given month?

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文