Adds a specified number of whole and fractional hours to the current DateTimeOffset object.
using System;
public class DateArithmetic
{
public static void Main()
{
int SHIFT_LENGTH = 8;
DateTimeOffset startTime = new DateTimeOffset(2010, 8, 6, 0, 0, 0, DateTimeOffset.Now.Offset);
DateTimeOffset startOfShift = startTime.AddHours(SHIFT_LENGTH);
Console.WriteLine("Shifts for the week of {0:D}", startOfShift);
do
{
Console.WriteLine("{0:d} at {0:T}", startOfShift);
startOfShift = startOfShift.AddHours(SHIFT_LENGTH);
} while (startOfShift.DayOfWeek != DayOfWeek.Saturday & startOfShift.DayOfWeek != DayOfWeek.Sunday);
}
}
Related examples in the same category