如何找到下一个八月?C#

use*_*964 1 c# datetime

我有以下问题:

我们需要找到下一个八月.换句话说,如果我们是2009-09-01我们需要2010-08-31如果我们是2009-06-21我们需要2009-08-31.

我知道我可以检查今天是否小于8月31日,但我想知道是否还有其他可能性.

BFr*_*ree 16

    public static class DateTimeExtensions
    {
        public static DateTime GetNextAugust31(this DateTime date)
        {
            return new DateTime(date.Month <= 8 ? date.Year : date.Year + 1, 8, 31);
        }
    }
Run Code Online (Sandbox Code Playgroud)