csharp 下个月更高的月份

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 下个月更高的月份相关的知识,希望对你有一定的参考价值。

<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Returns the next month day after the given DateTime.</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;T&quot;&gt;Source DateTime&lt;/param&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;D&quot;&gt;Target month day&lt;/param&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;returns&gt;DateTime&lt;/returns&gt;</span>
<span style="color: #0600FF;">public</span> DateTime NextHigherMonthDay<span style="color: #000000;">&#40;</span>DateTime T, <span style="color: #FF0000;">int</span> D<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>T.<span style="color: #0000FF;">Day</span> &gt;= D<span style="color: #000000;">&#41;</span> ? T.<span style="color: #0000FF;">AddMonths</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span> : T<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">AddDays</span><span style="color: #000000;">&#40;</span>D-T.<span style="color: #0000FF;">Day</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// With a minor change, you can create related functions like</span>
<span style="color: #008080; font-style: italic;">// the one below. I just changed the &quot;&gt;=&quot; to &quot;&gt;&quot; ...</span>
<span style="color: #0600FF;">public</span> DateTime NextHigherOrEqualMonthDay<span style="color: #000000;">&#40;</span>DateTime T, <span style="color: #FF0000;">int</span> D<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>T.<span style="color: #0000FF;">Day</span> &gt; D<span style="color: #000000;">&#41;</span> ? T.<span style="color: #0000FF;">AddMonths</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span> : T<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">AddDays</span><span style="color: #000000;">&#40;</span>D - T.<span style="color: #0000FF;">Day</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>

以上是关于csharp 下个月更高的月份的主要内容,如果未能解决你的问题,请参考以下文章

获取下个月的月份

在我当前订阅结束之前升级到更高的订阅时,订阅如何工作?

合计当前月份 + 2 AND 下个月 + 1 和之后的月份

Excel从列表中的选定月份获取下个月?

下个月,PHP 的同一天

PHP下获取上个月、下个月、本月的日期