Is there any easy way to increment a DateTime by monthly/yearly/daily units without having to parse it out like crazy?

前端 未结 4 1908
后悔当初
后悔当初 2020-12-20 22:08

I need to set up billing cycles and process payments. So for example I will process a payment immediately and then set the next one up to process exactly one month from then

相关标签:
4条回答
  • 2020-12-20 22:38

    The aptly-named "AddMonths" method comes immediately to mind.

    0 讨论(0)
  • 2020-12-20 22:48

    DateTime has a set of Add methods such as:

    • AddYears
    • AddMonths
    • AddDays
    • AddHours
    • AddMonths

    etc.

    More information at DateTime methods.

    0 讨论(0)
  • 2020-12-20 23:00

    Try this:

    DateTime myDateTime = DateTime.Now.AddMonths(1);
    
    0 讨论(0)
  • 2020-12-20 23:01

    If you ever need to work with Quarter or WeekOfYear, Microsoft.VisualBasic.DateAndTime.

    http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.dateandtime_members.aspx

    Otherwise, System.DateTime does everything you would typically need.

    0 讨论(0)
提交回复
热议问题