AddTimeSpan¶
Returns a new DateTimeOffset by adding a specified duration, considering calendar rules.
1 | |
Parameters¶
DateTimeOffset dateTime
The base DateTimeOffset value to add the duration to.
string duration
The duration to add, in either "d.hh:mm:ss" format or ISO-8601 duration format.
Returns¶
A new DateTimeOffset value representing the result of the addition, considering calendar rules.
Remarks¶
This method adds the given duration in business hours. If you only need to add the duration and find the next business date and time, please use the Calendar.GetDateTime method instead.
In addition to the ISO-8601 duration format, this method also supports begin and end specifiers for time periods:
BD: Begin of the dayDE: End of the dayMB: Begin of the monthME: End of the monthYB: Begin of the yearYE: End of the year
Examples:
P2BY: Adds 2 years to the current date and rolls back to the beginning of the year.P1M2BD: Adds 1 month and 2 days to the current date and rolls back to the beginning of the day.P1M2ED: Adds 1 month and 2 days to the current date and forwards to the end of the day.
Add an ISO-8601 duration using business-hour rules¶
1 2 | |
Add a time span using day-hour-minute-second format¶
1 2 | |
Warning
This method adds the duration in business hours and may skip non-business dates while adding the duration.
See how business hours shift the resulting time¶
1 2 | |
Compare equivalent duration formats¶
1 2 | |